Assume I have a Django model with the following fields:
class Gizmo(models.Model):
date_created = models.DateTimeField(auto_now_add=True)
date_updated = models.DateTimeField(auto_now=True)
When I create a gizmo, can I be sure that Django will generate identical timestamps for the two fields? I’m worried that Django might create a datetime instance for each, and that these will produce slightly different timestamps. It’s important that the timestamps be identical so that there’s a reliable way to determine whether the gizmo has been updated (i.e. it has been if the timestamps differ).
Based on one test I can tell you the answer is no.
I’d just override the save method on your model and populate these values myself.
PS: I did just look at the field code first, but ended up just running the actual test since I wouldn’t have known if django does something on a model level somewhere if there are two auto_now-type fields or something.