0

Following field gets updated whenever model_obj.save() happens.

   modified_at = models.DateTimeField(auto_now=True, db_index=True)

However, it is not updated when doing MyModel.objects.filter(id=model_obj.id).update(**kwargs)

Is there a way to somehow enforce updating modified_at?

eugene
  • 39,839
  • 68
  • 255
  • 489

1 Answers1

1

auto_now only updated when you call save() after update statement.

From Django Docs

Automatically set the field to now every time the object is saved. Useful for “last-modified” timestamps. Note that the current date is always used; it’s not just a default value that you can override.

The field is only automatically updated when calling Model.save(). The field isn’t updated when making updates to other fields in other ways such as QuerySet.update(), though you can specify a custom value for the field in an update like that.

Community
  • 1
  • 1
Vibhu
  • 157
  • 8