Мои модели Django
Я хочу сериализовать «Task Id» из таблицы «Task» при сериализации модели ошибок. Когда я сериализирую ошибку, я также хочу, чтобы он ассоциировал «taskId» как ответ JSON.
Модели -> Модель задач, Модель ошибок, Модель задач (Один к одному)
Модель задач
class Task(models.Model):
TASK_STATUS = (
('Not Assigned','Not Assigned'),
('Assigned','Assigned'),
('Completed','Completed'),
('Ready to Check', 'Ready to Check'),
('Bug Found', 'Bug Found'),
)
taskid = models.IntegerField(primary_key=True)
taskname = models.CharField(max_length=50)
task_status = models.CharField(max_length=50,choices=TASK_STATUS,default='Not Assigned')
description = models.TextField()
assignee = models.ForeignKey(Employee, on_delete=models.SET_NULL, null=True, blank=True, related_name='tassignee')
assigner = models.ForeignKey(Employee, on_delete=models.SET_NULL, null=True, blank=True, related_name='tassigner')
project_id = models.ForeignKey(Project, on_delete=models.CASCADE, null=True, blank=True)
class Meta:
ordering = ('taskid',)
def __str__(self):
return self.taskid,self.taskname
Модель ошибки
class Bug(models.Model):
STATUS = (
('Assigned','Assigned'),
('Reassigned','Reassigned'),
('Fixed','Fixed'),
)
SEVERITY = (
('Critical','Critical'),
('High','High'),
('Medium','Medium'),
('Low','Low'),
)
PRIORITY = (
('High','High'),
('Medium','Medium'),
('Low','Low'),
)
bugid = models.IntegerField(primary_key=True)
bugname = models.CharField(max_length=50)
description = models.TextField()
status = models.CharField(max_length=50, choices=STATUS,default='assig')
screenshot= models.URLField(max_length=200)
priority = models.CharField(max_length=50,choices=PRIORITY,default='M')
severity = models.CharField(max_length=50,choices=SEVERITY,default='M')
reporter = models.ForeignKey(Employee, on_delete=models.SET_NULL, null=True, blank=True,related_name='breporter')
assignee = models.ForeignKey(Employee, on_delete=models.SET_NULL, null=True, blank=True,related_name='bassignee')
bug_date = models.DateField(auto_now_add=True)
due_date = models.DateField()
Модель TaskBug
class TaskBug(models.Model):
task_id = models.ForeignKey(Task,on_delete=models.CASCADE, null=True, blank=True)
bug_id = models.ForeignKey(Bug, on_delete=models.CASCADE, null=True, blank=True)
class Meta:
unique_together = [['task_id','bug_id']]
ordering = ('task_id',)
def __str__(self):
return str(self.task_id)