我有一个模型来维护要进行的课程的批次列表,如下所示,
class CourseBatch(models.Model):
start_date = models.DateTimeField(null = True, blank = True)
end_date = models.DateTimeField(null = True, blank = True)
batch_name = models.CharField(max_length=50, default="Enter Batch Name")
course = models.ForeignKey(Course, on_delete=models.CASCADE, related_name="batches")
trainer = models.ForeignKey(Trainer, on_delete=models.CASCADE, related_name="trainer")
college = models.ForeignKey(College, on_delete=models.CASCADE, related_name="college")
additional_notes = models.TextField(max_length=500, default="No_Points",blank=True)
user = models.ForeignKey(User, verbose_name='user', on_delete=models.CASCADE, default=1)
objects = models.Manager()
def __str__(self):
return self.batch_name
每个批次都有一个关联的检查点列表,以维护该特定批次中已涵盖的主题列表,如下所示,
class ChkListForBatch(models.Model):
batch = models.ForeignKey(CourseBatch, on_delete=models.CASCADE, related_name="checklistitems")
chkpoint = models.ForeignKey(CheckPoint, on_delete=models.CASCADE, related_name="chkpoint")
chkpoint_done = models.BooleanField(default=False)
updated_on = models.DateTimeField(null = True, blank = True)
objects = models.Manager()
def __str__(self):
return self.chkpoint.description
我能够显示已添加超链接列的批次的列表视图,该列将用户带到特定批次的清单。现在的问题是我想以表格形式显示所有chkpoint和chkpoint_done字段,其中每行都有1个检查点和chkpoint_done字段的复选框。目前,我正在使用通用的updateview,该视图显示了带有模型中批处理和chkpoints项的下拉菜单的表单。