Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Re-added docs for QuerySet reverse() and all() methods, refs #9000 - …

…thanks ramiro

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9005 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f17f2bfd1fa1ac6f797c1d0aec1ac12b3bd7b051 1 parent 0cd7fbe
authored September 11, 2008

Showing 1 changed file with 34 additions and 4 deletions. Show diff stats Hide diff stats

  1. 38  docs/ref/models/querysets.txt
38  docs/ref/models/querysets.txt
@@ -7,9 +7,9 @@ QuerySet API reference
7 7
 .. currentmodule:: django.db.models
8 8
 
9 9
 This document describes the details of the ``QuerySet`` API. It builds on the
10  
-material presented in the :ref:`model <topics-db-models>` and `database query
11  
-<topics-db-queries>` guides, so you'll probably want to read and understand
12  
-those documents before reading this one.
  10
+material presented in the :ref:`model <topics-db-models>` and :ref:`database
  11
+query <topics-db-queries>` guides, so you'll probably want to read and
  12
+understand those documents before reading this one.
13 13
 
14 14
 Throughout this reference we'll use the :ref:`example weblog models
15 15
 <queryset-model-example>` presented in the :ref:`database query guide
@@ -192,6 +192,26 @@ There's no way to specify whether ordering should be case sensitive. With
192 192
 respect to case-sensitivity, Django will order results however your database
193 193
 backend normally orders them.
194 194
 
  195
+``reverse()``
  196
+~~~~~~~~~~~~~
  197
+
  198
+.. versionadded:: 1.0
  199
+
  200
+Use the ``reverse()`` method to reverse the order in which a queryset's
  201
+elements are returned. Calling ``reverse()`` a second time restores the
  202
+ordering back to the normal direction.
  203
+
  204
+To retrieve the ''last'' five items in a queryset, you could do this::
  205
+
  206
+    my_queryset.reverse()[:5]
  207
+
  208
+Note that this is not quite the same as slicing from the end of a sequence in
  209
+Python. The above example will return the last item first, then the
  210
+penultimate item and so on. If we had a Python sequence and looked at
  211
+``seq[-5:]``, we would see the fifth-last item first. Django doesn't support
  212
+that mode of access (slicing from the end), because it's not possible to do it
  213
+efficiently in SQL.
  214
+
195 215
 Also, note that ``reverse()`` should generally only be called on a
196 216
 ``QuerySet`` which has a defined ordering (e.g., when querying against
197 217
 a model which defines a default ordering, or when using
@@ -200,7 +220,6 @@ a model which defines a default ordering, or when using
200 220
 ordering was undefined prior to calling ``reverse()``, and will remain
201 221
 undefined afterward).
202 222
 
203  
-
204 223
 ``distinct()``
205 224
 ~~~~~~~~~~~~~~
206 225
 
@@ -393,6 +412,17 @@ Examples::
393 412
     >>> Entry.objects.none()
394 413
     []
395 414
 
  415
+``all()``
  416
+~~~~~~~~~~
  417
+
  418
+.. versionadded:: 1.0
  419
+
  420
+Returns a ''copy'' of the current ``QuerySet`` (or ``QuerySet`` subclass you
  421
+pass in). This can be useful in some situations where you might want to pass
  422
+in either a model manager or a ``QuerySet`` and do further filtering on the
  423
+result. You can safely call ``all()`` on either object and then you'll
  424
+definitely have a ``QuerySet`` to work with.
  425
+
396 426
 .. _select-related:
397 427
 
398 428
 ``select_related()``

0 notes on commit f17f2bf

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