What’s the difference between auto_now and auto_now_add?
auto_now
and auto_now_add
are two field options in Django that determine how the values of fields are set when a model instance is saved.
The auto_now
option is used to set the value of the field to the current date and time every time the model instance is saved, regardless of whether it is being created or updated. This is useful for fields that should always reflect the last time the instance was saved, such as a "last updated" timestamp.
The auto_now_add
option, on the other hand, is used to set the value of the field to the current date and time only when the model instance is created. This is useful for fields that should reflect the time the instance was created, such as a "date created" timestamp.
In summary, the key difference between auto_now
and auto_now_add
is that auto_now
updates the field value every time the instance is saved, while auto_now_add
sets the field value only when the instance is created.