From e1a6b4a2b45141d3ecac03c25ba99837b79bf68b Mon Sep 17 00:00:00 2001
From: Derek Willis <dwillis@gmail.com>
Date: Wed, 8 Sep 2010 21:41:45 -0400
Subject: [PATCH] Added update to QuerySet reference
---
docs/ref/models/querysets.txt | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index 87680d3..083cdb6 100644
a
|
b
|
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()`` |
| 1225 | ~~~~~~~~~~~~ |
| 1226 | |
| 1227 | .. method:: update() |
| 1228 | |
| 1229 | .. versionadded:: 1.0 |
| 1230 | |
| 1231 | Returns the number of rows affected by a SQL update query. The ``update()`` method |
| 1232 | is applied instantly and the only restriction on the QuerySet that is updated is |
| 1233 | that it can only access one database table, the model's main table. You can filter |
| 1234 | based on related fields, but you can only update columns in the model's main table. |
| 1235 | For example, if you wanted to update all blog entries to use the same headline:: |
| 1236 | |
| 1237 | >>> b = Blog.objects.get(pk=1) |
| 1238 | |
| 1239 | # Update all the headlines belonging to this Blog. |
| 1240 | >>> Entry.objects.select_related().filter(blog=b).update(headline='Everything is the same') |
| 1241 | |
| 1242 | The ``update()`` method does bulk updates and does not call any ``save()`` methods |
| 1243 | on your models, or emit the ``pre_save`` or ``post_save``signals |
| 1244 | (which are a consequence of calling ``save()``). |
| 1245 | |
1224 | 1246 | .. _field-lookups: |
1225 | 1247 | |
1226 | 1248 | Field lookups |