diff options
| author | Tim Graham <timograham@gmail.com> | 2016-06-21 13:46:22 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-21 14:39:17 -0400 |
| commit | 20d1cb33c2ec1242e16c49deb88e8c70517b2d1a (patch) | |
| tree | 06b35c67c0e5cc5f39c4e9863b6cdb1b227a3f8b /docs/ref | |
| parent | 9c2d5a8d333277cc1b482a9d05f174cf4d09f24c (diff) | |
Fixed #26787 -- Documented deleting and reloading of model instance fields.
Thanks Julien Hartmann for the report.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/instances.txt | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index 3b62675294..f0decc28d8 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -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 |
