1๐
โ
TL;DR: when you create an object for the first time, both created_at
and updated_at
will be filled with values, accordingly to the code you crafted.
- The
auto_now_add
will set thetimezone.now()
only when the instance is created. - The
auto_now
will update the field every time the save method is called.
However, both functions the same way by triggering the field update event with timezone.now()
.
This means that when you create an object for the first time, both created_at
and updated_at will
be filled with values.
But, the next time you save that object, the created_at will remain the same, while the updated_at will call the timezone.now()
.
The options auto_now_add, auto_now, and default are mutually exclusive. Any combination of these options will result in an error.
Django docs: https://docs.djangoproject.com/en/4.0/ref/models/fields/
๐คCarlo
Source:stackexchange.com