opal icon indicating copy to clipboard operation
opal copied to clipboard

Tracked model use auto add now fields

Open fredkingham opened this issue 7 years ago • 2 comments

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.

fredkingham avatar Jan 07 '18 16:01 fredkingham

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.

ghickman avatar Jan 17 '19 08:01 ghickman

👍

BTW I think they auto add now does work on bulk create. I wasn't sure so I did the below test.

screen shot 2019-01-17 at 13 45 56 screen shot 2019-01-17 at 13 45 48

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...)

screen shot 2019-01-17 at 13 51 42

fredkingham avatar Jan 17 '19 13:01 fredkingham