models.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from django.db import models
  2. # Create your models here.
  3. from apps.software.models import Software
  4. from apps.user.models import User
  5. class TestPlan(models.Model):
  6. id = models.CharField(max_length=128, unique=True, primary_key=True, verbose_name='测试计划编号',
  7. default='TestLaboratory_V1_Plan_1')
  8. title = models.CharField(max_length=30, verbose_name='测试计划标题')
  9. type = models.CharField(max_length=30, verbose_name='测试计划类型', null=True)
  10. software = models.ForeignKey(Software, on_delete=models.CASCADE, verbose_name='测试软件')
  11. version = models.CharField(max_length=20, verbose_name='软件版本')
  12. creator = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, verbose_name='测试计划执行者')
  13. state = models.IntegerField(verbose_name='测试计划执行状态')
  14. description = models.TextField(verbose_name='测试计划描述')
  15. statement_file = models.TextField(verbose_name='说明文档id路径')
  16. create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
  17. update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
  18. delete = models.BooleanField(default=False)
  19. def __str__(self):
  20. return self.title
  21. class Meta:
  22. verbose_name = '测试计划'
  23. verbose_name_plural = verbose_name
  24. db_table = 'plan'
  25. # def save_files(files, plan_id, time_stamp):
  26. # """
  27. #
  28. # """
  29. # fids = []
  30. # file_paths = []
  31. # for file in files:
  32. # try:
  33. # file_dir = PLAN_ROOT + "/" + plan_id + "/" + str(time_stamp)
  34. # if not os.path.exists(file_dir):
  35. # os.makedirs(file_dir)
  36. # file_path = file_dir + "/" + file.name
  37. # with open(file_path, 'wb') as f:
  38. # f.write(file.read())
  39. # f.close()
  40. # except:
  41. # return 0
  42. #
  43. # if not FileManager.objects.last():
  44. # id_file = "TestLaboratory_V1_File_1"
  45. # else:
  46. # id_file = gen_next_id(FileManager.objects.order_by('create_time').last().id)
  47. #
  48. # try:
  49. # file_new = FileManager.objects.create(id=id_file, category="plan_statement",
  50. # path=plan_id + "/" + str(time_stamp) + "/" + file.name,
  51. # create_time=time_stamp,
  52. # update_time=time_stamp)
  53. # except:
  54. # return 1
  55. # file_paths.append(PLAN_ROOT + file_new.path)
  56. # fids.append(id_file)
  57. # return file_paths, fids