opal
opal copied to clipboard
Tracked model use auto add now fields
at the moment we use the serialisers to track who has updated/created timestamps.
Change this to use https://docs.djangoproject.com/en/2.0/ref/models/fields/#django.db.models.DateField
you might decide to pass in a
default lambda of timezone.now instead of auto add now as the default allowing the user to choose whether they want to the updated time stamp enforced by the database.
Migrations will be required on all plugins (that contain models) and applications.
You might want to avoid auto_now
and auto_now_add
since neither fire when bulk creating models and as you pointed out they stop you overriding a field.
I think default=timezone.now
makes sense, you get the benefits of the auto_now[_add]
attributes without the downsides.
👍
BTW I think they auto add now does work on bulk create. I wasn't sure so I did the below test.
I was told that auto_add_now was ignored by fixtures, therefore you should use it if for some reason when you imported fixtures you wanted to have the date that you added the fixture rather than the previous date.
However that appears to not be the case (on sqlite anyway...)