Skip to content

Commit

Permalink
[1.9.x] Refs #23386 -- Documented that F() expressions are applied on…
Browse files Browse the repository at this point in the history
… each model.save()

Backport of fc4b4fd from master
  • Loading branch information
Tsering authored and timgraham committed Jun 28, 2016
1 parent e1d83c2 commit 67c60cc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/ref/models/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ robust: it will only ever update the field based on the value of the field in
the database when the :meth:`~Model.save()` or ``update()`` is executed, rather
than based on its value when the instance was retrieved.

``F()`` assignments persist after ``Model.save()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``F()`` objects assigned to model fields persist after saving the model
instance and will be applied on each :meth:`~Model.save()`. For example::

reporter = Reporters.objects.get(name='Tintin')
reporter.stories_filed = F('stories_filed') + 1
reporter.save()

reporter.name = 'Tintin Jr.'
reporter.save()

``stories_filed`` will be updated twice in this case. If it's initially ``1``,
the final value will be ``3``.

Using ``F()`` in filters
~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit 67c60cc

Please sign in to comment.