Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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
  • Loading branch information...
commit 7c1671b4803a4ca78540a288a14eb2ec8ba74d80 1 parent b9d1c5d
Russell Keith-Magee authored February 23, 2010

Showing 1 changed file with 8 additions and 3 deletions. Show diff stats Hide diff stats

  1. 11  docs/topics/db/queries.txt
11  docs/topics/db/queries.txt
@@ -778,7 +778,7 @@ a ``QuerySet``. You can do this with the ``update()`` method. For example::
778 778
 You can only set non-relation fields and ``ForeignKey`` fields using this
779 779
 method. To update a non-relation field, provide the new value as a constant.
780 780
 To update ``ForeignKey`` fields, set the new value to be the new model
781  
-instance you want to point to. Example::
  781
+instance you want to point to. For example::
782 782
 
783 783
     >>> b = Blog.objects.get(pk=1)
784 784
 
@@ -788,8 +788,13 @@ instance you want to point to. Example::
788 788
 The ``update()`` method is applied instantly and doesn't return anything
789 789
 (similar to ``delete()``). The only restriction on the ``QuerySet`` that is
790 790
 updated is that it can only access one database table, the model's main
791  
-table. So don't try to filter based on related fields or anything like that;
792  
-it won't work.
  791
+table. You can filter based on related fields, but you can only update columns
  792
+in the model's main table. Example::
  793
+
  794
+    >>> b = Blog.objects.get(pk=1)
  795
+
  796
+    # Update all the headlines belonging to this Blog.
  797
+    >>> Entry.objects.select_related().filter(blog=b).update(headline='Everything is the same')
793 798
 
794 799
 Be aware that the ``update()`` method is converted directly to an SQL
795 800
 statement. It is a bulk operation for direct updates. It doesn't run any

0 notes on commit 7c1671b

Please sign in to comment.
Something went wrong with that request. Please try again.