1
我添加了一個save()
方法我Model
,更新一些時間戳:Model.save()不要求更新()
class Order(models.Model):
deliveredtime = models.DateTimeField(blank=True, null=True, default=None)
status = models.CharField(default='NEW', max_length=20)
def save(self, *args, **kw):
if self.status == "DELIVERED" and self.deliveredtime is None:
self.deliveredtime = timezone.now()
super(Order, self).save(*args, **kw)
但我發現名單上調用update
此方法時,不叫的對象:
Order.objects.filter(status='WAITING FOR DELIVERY').update(status='DELIVERED')
如何觸發此更新對Order
類的任何對象的任何更改?