mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #26787 -- Documented deleting and reloading of model instance fields.
Thanks Julien Hartmann for the report.
This commit is contained in:
@@ -128,6 +128,18 @@ in the ``from_db()`` method.
|
||||
Refreshing objects from database
|
||||
================================
|
||||
|
||||
If you delete a field from a model instance, accessing it again reloads the
|
||||
value from the database::
|
||||
|
||||
>>> obj = MyModel.objects.first()
|
||||
>>> del obj.field
|
||||
>>> obj.field # Loads the field from the database
|
||||
|
||||
.. versionchanged:: 1.10
|
||||
|
||||
In older versions, accessing a deleted field raised ``AttributeError``
|
||||
instead of reloading it.
|
||||
|
||||
.. method:: Model.refresh_from_db(using=None, fields=None)
|
||||
|
||||
If you need to reload a model's values from the database, you can use the
|
||||
|
||||
@@ -884,6 +884,9 @@ Miscellaneous
|
||||
* The ``_base_manager`` and ``_default_manager`` attributes are removed from
|
||||
model instances. They remain accessible on the model class.
|
||||
|
||||
* Accessing a deleted field on a model instance, e.g. after ``del obj.field``,
|
||||
reloads the field's value instead of raising ``AttributeError``.
|
||||
|
||||
.. _deprecated-features-1.10:
|
||||
|
||||
Features deprecated in 1.10
|
||||
|
||||
Reference in New Issue
Block a user