数据模型:
class Task(models.Model): taskStartTime = models.DateTimeField(verbose_name='开始时间') taskEndTime = models.DateTimeField(verbose_name='结束时间') def __str__(self): return self.taskName
添加约束:
class Task(models.Model): taskStartTime = models.DateTimeField(verbose_name='开始时间') taskEndTime = models.DateTimeField(verbose_name='结束时间') class Meta: verbose_name = '任务管理' verbose_name_plural = verbose_name constraints = [ models.CheckConstraint( check=Q(taskStartTime__lte=F('taskEndTime')), name='datetimecheck' ), ] def __str__(self): return self.taskName
评论 (0)