[1.1.X] Fixed #12859 -- Clarified the documentation on using multiple tables with .update() calls. Thanks to dwillis for the report.
Backport of r12515 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12520 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b9d1c5d9f6
commit
7c1671b480
|
@ -778,7 +778,7 @@ a ``QuerySet``. You can do this with the ``update()`` method. For example::
|
||||||
You can only set non-relation fields and ``ForeignKey`` fields using this
|
You can only set non-relation fields and ``ForeignKey`` fields using this
|
||||||
method. To update a non-relation field, provide the new value as a constant.
|
method. To update a non-relation field, provide the new value as a constant.
|
||||||
To update ``ForeignKey`` fields, set the new value to be the new model
|
To update ``ForeignKey`` fields, set the new value to be the new model
|
||||||
instance you want to point to. Example::
|
instance you want to point to. For example::
|
||||||
|
|
||||||
>>> b = Blog.objects.get(pk=1)
|
>>> b = Blog.objects.get(pk=1)
|
||||||
|
|
||||||
|
@ -788,8 +788,13 @@ instance you want to point to. Example::
|
||||||
The ``update()`` method is applied instantly and doesn't return anything
|
The ``update()`` method is applied instantly and doesn't return anything
|
||||||
(similar to ``delete()``). The only restriction on the ``QuerySet`` that is
|
(similar to ``delete()``). The only restriction on the ``QuerySet`` that is
|
||||||
updated is that it can only access one database table, the model's main
|
updated is that it can only access one database table, the model's main
|
||||||
table. So don't try to filter based on related fields or anything like that;
|
table. You can filter based on related fields, but you can only update columns
|
||||||
it won't work.
|
in the model's main table. Example::
|
||||||
|
|
||||||
|
>>> b = Blog.objects.get(pk=1)
|
||||||
|
|
||||||
|
# Update all the headlines belonging to this Blog.
|
||||||
|
>>> Entry.objects.select_related().filter(blog=b).update(headline='Everything is the same')
|
||||||
|
|
||||||
Be aware that the ``update()`` method is converted directly to an SQL
|
Be aware that the ``update()`` method is converted directly to an SQL
|
||||||
statement. It is a bulk operation for direct updates. It doesn't run any
|
statement. It is a bulk operation for direct updates. It doesn't run any
|
||||||
|
|
Loading…
Reference in New Issue