Browse files

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

…thanks ramiro

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 0cd7fbe commit f17f2bfd1fa1ac6f797c1d0aec1ac12b3bd7b051 Simon Willison committed Sep 11, 2008
Showing with 34 additions and 4 deletions.
  1. +34 −4 docs/ref/models/querysets.txt
@@ -7,9 +7,9 @@ QuerySet API reference
.. currentmodule:: django.db.models
This document describes the details of the ``QuerySet`` API. It builds on the
-material presented in the :ref:`model <topics-db-models>` and `database query
-<topics-db-queries>` guides, so you'll probably want to read and understand
-those documents before reading this one.
+material presented in the :ref:`model <topics-db-models>` and :ref:`database
+query <topics-db-queries>` guides, so you'll probably want to read and
+understand those documents before reading this one.
Throughout this reference we'll use the :ref:`example weblog models
<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
respect to case-sensitivity, Django will order results however your database
backend normally orders them.
+.. versionadded:: 1.0
+Use the ``reverse()`` method to reverse the order in which a queryset's
+elements are returned. Calling ``reverse()`` a second time restores the
+ordering back to the normal direction.
+To retrieve the ''last'' five items in a queryset, you could do this::
+ my_queryset.reverse()[:5]
+Note that this is not quite the same as slicing from the end of a sequence in
+Python. The above example will return the last item first, then the
+penultimate item and so on. If we had a Python sequence and looked at
+``seq[-5:]``, we would see the fifth-last item first. Django doesn't support
+that mode of access (slicing from the end), because it's not possible to do it
+efficiently in SQL.
Also, note that ``reverse()`` should generally only be called on a
``QuerySet`` which has a defined ordering (e.g., when querying against
a model which defines a default ordering, or when using
@@ -200,7 +220,6 @@ a model which defines a default ordering, or when using
ordering was undefined prior to calling ``reverse()``, and will remain
undefined afterward).
@@ -393,6 +412,17 @@ Examples::
>>> Entry.objects.none()
+.. versionadded:: 1.0
+Returns a ''copy'' of the current ``QuerySet`` (or ``QuerySet`` subclass you
+pass in). This can be useful in some situations where you might want to pass
+in either a model manager or a ``QuerySet`` and do further filtering on the
+result. You can safely call ``all()`` on either object and then you'll
+definitely have a ``QuerySet`` to work with.
.. _select-related:

0 comments on commit f17f2bf

Please sign in to comment.