From be03ce25c4bdf3fc5b413e6ca83edb4661cf608d Mon Sep 17 00:00:00 2001 From: Tsering Date: Sat, 23 Apr 2016 16:38:57 -0400 Subject: [1.10.x] Refs #23386 -- Documented that F() expressions are applied on each model.save() Backport of fc4b4fd5850989458d6e54de12a29b2e40e94ce8 from master --- docs/ref/models/expressions.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'docs/ref/models') diff --git a/docs/ref/models/expressions.txt b/docs/ref/models/expressions.txt index 6c767658af..69fad99f47 100644 --- a/docs/ref/models/expressions.txt +++ b/docs/ref/models/expressions.txt @@ -170,6 +170,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 ~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.3