Django

Code

Changeset 7489

Show
Ignore:
Timestamp:
04/27/08 19:59:09 (2 months ago)
Author:
adrian
Message:

Edited some docs/db-api.txt changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/db-api.txt

    r7480 r7489  
    528528 
    529529**New in Django development version:** The syntax for ordering across related 
    530 models has changed. See the `Django 0.96 documentation`_ for the old behaviour. 
     530models has changed. See the `Django 0.96 documentation`_ for the old behavior. 
    531531 
    532532.. _Django 0.96 documentation: http://www.djangoproject.com/documentation/0.96/model-api/#floatfield 
     
    541541**New in Django development version** 
    542542 
    543 If you want to reverse the order in which a queryset's elements are returned, 
    544 you can use the ``reverse()`` method. Calling ``reverse()`` a second tim
    545 restores the ordering back to the normal direction. 
     543Use the ``reverse()`` method to reverse the order in which a queryset's 
     544elements are returned. Calling ``reverse()`` a second time restores th
     545ordering back to the normal direction. 
    546546 
    547547To retrieve the ''last'' five items in a queryset, you could do this:: 
     
    553553penultimate item and so on. If we had a Python sequence and looked at 
    554554``seq[:-5]``, we would see the fifth-last item first. Django doesn't support 
    555 that mode of access (slicing from the end), since it is not possible to do it 
     555that mode of access (slicing from the end), because it's not possible to do it 
    556556efficiently in SQL. 
    557557 
     
    16611661filter statement, not the ``Entry`` items. 
    16621662 
    1663 All of this behaviour also applies to ``exclude()``: all the conditions in a 
     1663All of this behavior also applies to ``exclude()``: all the conditions in a 
    16641664single ``exclude()`` statement apply to a single instance (if those conditions 
    16651665are talking about the same multi-valued relation). Conditions in subsequent 
     
    21022102 
    21032103Sometimes you want to set a field to a particular value for all the objects in 
    2104 a queryset. You can do this with the ``update()`` method. For example:: 
    2105  
    2106     # Update all the headlines to the same value
    2107     Entry.objects.all().update(headline='Everything is the same') 
     2104a ``QuerySet``. You can do this with the ``update()`` method. For example:: 
     2105 
     2106    # Update all the headlines with pub_date in 2007
     2107    Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same') 
    21082108 
    21092109You can only set non-relation fields and ``ForeignKey`` fields using this 
    2110 method and the value you set the field to must be a normal Python value (you 
    2111 can't set a field to be equal to some other field at the moment). 
     2110method, and the value you set the field to must be a hard-coded Python value 
     2111(i.e., you can't set a field to be equal to some other field at the moment). 
    21122112 
    21132113To update ``ForeignKey`` fields, set the new value to be the new model 
     
    21152115 
    21162116    b = Blog.objects.get(pk=1) 
    2117     # Make all entries belong to this blog. 
     2117    # Change every Entry so that it belongs to this Blog. 
    21182118    Entry.objects.all().update(blog=b) 
    21192119 
    21202120The ``update()`` method is applied instantly and doesn't return anything 
    2121 (similar to ``delete()``). The only restriction on the queryset that is 
     2121(similar to ``delete()``). The only restriction on the ``QuerySet`` that is 
    21222122updated is that it can only access one database table, the model's main 
    21232123table. So don't try to filter based on related fields or anything like that;