Ticket #14004: 14004.diff

File 14004.diff, 1.6 KB (added by Derek Willis, 14 years ago)
  • docs/ref/models/querysets.txt

    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  
    12211221more overall work (an additional query) than simply using
    12221222``bool(some_query_set)``.
    12231223
     1224``update()``
     1225~~~~~~~~~~~~
     1226
     1227.. method:: update()
     1228
     1229.. versionadded:: 1.0
     1230
     1231Returns the number of rows affected by a SQL update query. The ``update()`` method
     1232is applied instantly and the only restriction on the QuerySet that is updated is
     1233that it can only access one database table, the model's main table. You can filter
     1234based on related fields, but you can only update columns in the model's main table.
     1235For 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
     1242The ``update()`` method does bulk updates and does not call any ``save()`` methods
     1243on your models, or emit the ``pre_save`` or ``post_save``signals
     1244(which are a consequence of calling ``save()``).
     1245
    12241246.. _field-lookups:
    12251247
    12261248Field lookups
Back to Top