karanlyons / django-save-the-change

Your DB Got It the First Time.
http://django-save-the-change.readthedocs.io
Other
114 stars 29 forks source link

Django datetime fields with (auto_now=True) don't get updated #17

Closed binit-singh closed 8 years ago

binit-singh commented 8 years ago

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.

karanlyons commented 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.