Closed binit-singh closed 8 years ago
auto_now
and auto_now_add
are handled by date/time fields’ pre_save()
method. Since this is called at the end of a model’s save()
method (specifically it’s not handled until the underlying sql query is built, there’s really no way at all (at least that I can currently think of) to properly handle this behavior with any sort of mixin.
It’s for reasons like this that those parameters are actually deprecated, as is the use of pre_save()
for anything more than just data transformations.
DemoTable(SaveTheChange, models.Model): demo_name = models.CharField(max_length=50) modified_at = models.DateTimeField(auto_now=True)
demo_obj = DemoTable.objects.get(id=1) demo_obj.demo_name = 'abc' demo_obj.save()
It does not updates modified_at field.