






import pathlib
from re import match
from django.db import models
# Create your models here.
from django.utils import html
class Task(models.Model):
name = models.CharField("用例名称", max_length=20)
print(name)
case = models.FileField("用例文件", upload_to='tests/%Y_%m_%d_%H_%M_%S/')
print(case)
status = models.IntegerField(
"测试状态", default=-1, choices=[
(-1, '初始化'),
(0, '马上执行'),
(1, '正在执行测试用例'),
(2, '正在生成测试报告'),
(3, '执行完成')
]
)
run_datatime = models.DateTimeField("最近执行时间", null=True, blank=True)
class Mate: # 内部类:https://www.cnblogs.com/yum777/articles/8992640.html
verbose_name_plural = verbose_name = '测试任务'
def get_url(self, _type):
"""生成报告、或者测试日志的url"""
print(_type)
if self.case and self.status==3:
case_path = pathlib.PurePosixPath(str(self.case))
print(case_path)
root_path = pathlib.PurePosixPath("/uploads")
# python3.10 以后才能用 新特性 match-case,这里的环境是3.7;
if _type=='report':
report_path = root_path / case_path.parent / "report/index.html"
print("report_path: {}".format(report_path))
elif _type == '':
report_path = root_path / case_path.parent / "pytest.txt"
print("report_path: {}".format(report_path))
elif _:
report_path = '_'
print("report_path: {}".format(report_path))
return html.format_html(f" 点击查看")
else:
return "-"
cmd输入命令:python manage.py makemigrations (执行该命令才能让定义的model真正产生作用)

生成迁移脚本后需要输入:“python manage.py migrate” 命令来执行迁移脚本

2. 定义界面
python manage.py createsuperuser