Fix docs for model.save() with update_fields specified and auto_now field in model

61 views
Skip to first unread message

Sebastian Haase

unread,
Mar 25, 2019, 11:30:57 AM3/25/19
to Django users
Hi,
in section "Specifying which fields to save" (https://docs.djangoproject.com/en/dev/ref/models/instances/#specifying-which-fields-to-save) it reads that `update_fields` can be specified mostly for performance benefits...
However, I found that regarding a field with "auto_now=True" there is a different outcome.
IOW, specifying `update_fields` can be used to keep the old date in respective  "auto_now=True"-field UNLESS that field is also explicitly given un `update_fields`

I hope I got this correct - at least that was the impression from my own tests with Django 2.1. Than this should be more prominently stated in the documentation.

Thanks for Django.
Sebastian

Sebastian Haase

unread,
Mar 25, 2019, 11:33:13 AM3/25/19
to Django users
There are of course stackoverflow postings -e.g. https://stackoverflow.com/questions/17474057/enforce-auto-now-when-using-saveupdate-fields - is almost 6 years old.

Sebastian Haase

unread,
Mar 28, 2019, 7:07:42 AM3/28/19
to Django users
Please advise if this is the right place to report such a doc enhancement request - anyone?

BTW - in addition I also noticed that - using deserialization - object.save() gives unexpected different results for auto_now field: 
 - if the object-pk aleady existed , the field is saved as given 
 - but if it did not exist, the given value is ignored, and the current time is used instead 
... very strange if you ask me...

Cheers,
Sebastian


--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/sqMrUlZP2-8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0eabc3b1-ac4b-491b-a44b-0db1e611e85e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages