Why are DateTimeField auto_now and auto_now_add bad?

108 views
Skip to first unread message

Mattias Linnap

unread,
Jul 27, 2014, 10:29:29 AM7/27/14
to django...@googlegroups.com
Hi all,

I've seen DateTimeField's auto_now and auto_now_add parameters often described as "buggy" or "error-prone". For example:

The ticket proposes to document these downsides or problems in more detail. But until that happens, is there a blog post or mailing list post somewhere that summarises the gotchas to watch out for with auto_now?

Thanks,

Mattias

Russell Keith-Magee

unread,
Jul 27, 2014, 6:47:33 PM7/27/14
to Django Users

I'm not aware of a formally documented list anywhere. 

To the best my knowledge, the bug/downside that is referred to here is that the fields *won't* automatically update in *every* circumstance. You need to actually *save* the model to make the field update. Calls to update, save_base, etc won't invoke the "auto" part of the field logic, and the timestamp won't be adjusted.

Yours,
Russ Magee %-)


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9d61eca2-21c7-41ae-a921-a448d5f9f4f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

cmawe...@gmail.com

unread,
Jul 31, 2014, 12:11:38 PM7/31/14
to django...@googlegroups.com
It gets confusing if those fields are editable in the admin. I recommend setting editable=False on those fields.
Reply all
Reply to author
Forward
0 new messages