mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #18306 -- Made deferred models issue update_fields on save
Deferred models now automatically update only the fields which are loaded from the db (with .only() or .defer()). In addition, any field set manually after the load is updated on save.
This commit is contained in:
parent
59a655988e
commit
99321e30ce
7 changed files with 161 additions and 0 deletions
|
@ -386,6 +386,12 @@ perform an update on all fields.
|
|||
|
||||
Specifying ``update_fields`` will force an update.
|
||||
|
||||
When saving a model fetched through deferred model loading
|
||||
(:meth:`~Model.only()` or :meth:`~Model.defer()`) only the fields loaded from
|
||||
the DB will get updated. In effect there is an automatic ``update_fields`` in
|
||||
this case. If you assign or change any deferred field value, these fields will
|
||||
be added to the updated fields.
|
||||
|
||||
Deleting objects
|
||||
================
|
||||
|
||||
|
|
|
@ -1110,6 +1110,14 @@ one, doing so will result in an error.
|
|||
reader, is slightly faster and consumes a little less memory in the Python
|
||||
process.
|
||||
|
||||
.. versionchanged:: 1.5
|
||||
|
||||
.. note::
|
||||
|
||||
When calling :meth:`~Model.save()` for instances with deferred fields,
|
||||
only the loaded fields will be saved. See :meth:`~Model.save()` for more
|
||||
details.
|
||||
|
||||
|
||||
only
|
||||
~~~~
|
||||
|
@ -1154,6 +1162,14 @@ All of the cautions in the note for the :meth:`defer` documentation apply to
|
|||
options. Also note that using :meth:`only` and omitting a field requested
|
||||
using :meth:`select_related` is an error as well.
|
||||
|
||||
.. versionchanged:: 1.5
|
||||
|
||||
.. note::
|
||||
|
||||
When calling :meth:`~Model.save()` for instances with deferred fields,
|
||||
only the loaded fields will be saved. See :meth:`~Model.save()` for more
|
||||
details.
|
||||
|
||||
using
|
||||
~~~~~
|
||||
|
||||
|
|
|
@ -42,6 +42,10 @@ keyword argument ``update_fields``. By using this argument it is possible to
|
|||
save only a select list of model's fields. This can be useful for performance
|
||||
reasons or when trying to avoid overwriting concurrent changes.
|
||||
|
||||
Deferred instances (those loaded by .only() or .defer()) will automatically
|
||||
save just the loaded fields. If any field is set manually after load, that
|
||||
field will also get updated on save.
|
||||
|
||||
See the :meth:`Model.save() <django.db.models.Model.save()>` documentation for
|
||||
more details.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue