我有一个模型Idea
我想触发它验证的日期。如何告诉django每次Field
状态更新为validated
时自动写入验证日期?
答案 0 :(得分:0)
@receiver(pre_save, sender=Proposition)
def proposition_update_handler(sender, instance, *args, **kwargs):
if instance.state=='validée':
instance.validation_date = datetime.now()
elif instance.state=='réalisée':
instance.execution_date = datetime.now()
elif instance.state=='clôturée':
instance.closing_date = datetime.now()
elif instance.state=='rejetée':
instance.rejection_date = datetime.now()