Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Adds documentation for QuerySet.update() method. Thanks to dw…

…illis and timo for the majority of the wording.

Backport of [14074] from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14075 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a96e50b76b38edb94356bb5d346ef96067175906 1 parent 91310e7
authored

Showing 1 changed file with 25 additions and 0 deletions. Show diff stats Hide diff stats

  1. 25  docs/ref/models/querysets.txt
25  docs/ref/models/querysets.txt
@@ -1221,6 +1221,31 @@ that it will be at some point, then using ``some_query_set.exists()`` will do
1221 1221
 more overall work (an additional query) than simply using
1222 1222
 ``bool(some_query_set)``.
1223 1223
 
  1224
+``update(**kwargs)``
  1225
+~~~~~~~~~~~~~~~~~~~~
  1226
+
  1227
+.. method:: update(**kwargs)
  1228
+
  1229
+Performs an SQL update query for the specified fields, and returns
  1230
+the number of rows affected. The ``update()`` method is applied instantly and
  1231
+the only restriction on the :class:`QuerySet` that is updated is that it can
  1232
+only update columns in the model's main table. Filtering based on related
  1233
+fields is still possible. You cannot call ``update()`` on a
  1234
+:class:`QuerySet` that has had a slice taken or can otherwise no longer be 
  1235
+filtered.
  1236
+
  1237
+For example, if you wanted to update all the entries in a particular blog
  1238
+to use the same headline::
  1239
+
  1240
+    >>> b = Blog.objects.get(pk=1)
  1241
+
  1242
+    # Update all the headlines belonging to this Blog.
  1243
+    >>> Entry.objects.select_related().filter(blog=b).update(headline='Everything is the same')
  1244
+
  1245
+The ``update()`` method does a bulk update and does not call any ``save()``
  1246
+methods on your models, nor does it emit the ``pre_save`` or ``post_save``
  1247
+signals (which are a consequence of calling ``save()``).
  1248
+
1224 1249
 .. _field-lookups:
1225 1250
 
1226 1251
 Field lookups

0 notes on commit a96e50b

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