Changeset 7489 for django/trunk/docs
- Timestamp:
- 04/27/08 19:59:09 (7 months ago)
- Files:
-
- django/trunk/docs/db-api.txt (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/db-api.txt
r7480 r7489 528 528 529 529 **New in Django development version:** The syntax for ordering across related 530 models has changed. See the `Django 0.96 documentation`_ for the old behavio ur.530 models has changed. See the `Django 0.96 documentation`_ for the old behavior. 531 531 532 532 .. _Django 0.96 documentation: http://www.djangoproject.com/documentation/0.96/model-api/#floatfield … … 541 541 **New in Django development version** 542 542 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 time545 restores theordering back to the normal direction.543 Use the ``reverse()`` method to reverse the order in which a queryset's 544 elements are returned. Calling ``reverse()`` a second time restores the 545 ordering back to the normal direction. 546 546 547 547 To retrieve the ''last'' five items in a queryset, you could do this:: … … 553 553 penultimate item and so on. If we had a Python sequence and looked at 554 554 ``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 it555 that mode of access (slicing from the end), because it's not possible to do it 556 556 efficiently in SQL. 557 557 … … 1661 1661 filter statement, not the ``Entry`` items. 1662 1662 1663 All of this behavio ur also applies to ``exclude()``: all the conditions in a1663 All of this behavior also applies to ``exclude()``: all the conditions in a 1664 1664 single ``exclude()`` statement apply to a single instance (if those conditions 1665 1665 are talking about the same multi-valued relation). Conditions in subsequent … … 2102 2102 2103 2103 Sometimes 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')2104 a ``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') 2108 2108 2109 2109 You 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 (you2111 can't set a field to be equal to some other field at the moment).2110 method, 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). 2112 2112 2113 2113 To update ``ForeignKey`` fields, set the new value to be the new model … … 2115 2115 2116 2116 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. 2118 2118 Entry.objects.all().update(blog=b) 2119 2119 2120 2120 The ``update()`` method is applied instantly and doesn't return anything 2121 (similar to ``delete()``). The only restriction on the querysetthat is2121 (similar to ``delete()``). The only restriction on the ``QuerySet`` that is 2122 2122 updated is that it can only access one database table, the model's main 2123 2123 table. So don't try to filter based on related fields or anything like that;
