每次有这个模型的INSERT / UPDATE时,我想检查'personprofile'是否已经承诺在那个日期工作了多天?
通过'已提交',我的意思是我只希望更新在完成后,PersonRequirement
的所有personprofile
实例的总数date
继续相同class PersonRequirement(models.Model):
'''
Joins a person to a Subproject on a given
day and nominates how much of that day
they are required for
'''
subproject = models.ForeignKey(SubProject, on_delete=models.CASCADE)
personprofile = models.ForeignKey(PersonProfile, on_delete=models.CASCADE)
date = models.DateField()
proportion_of_day_required = models.DecimalField(max_digits=3, decimal_places=2)
且相同{{1}}为1.0或更低。
{{1}}
我正在查看模型上的save方法但是我不确定在尝试插入/更新同一模型的实例时是否可以尝试读取同一模型的其他实例?
也许有一种我忽略的更好的方式?
答案 0 :(得分:0)
使用此自定义方法。每次完成保存(包括更新
)时,都会使用相同的自定义方法创建手动逻辑答案 1 :(得分:0)