Ticket #9000: doc-fixes-r8995-2.diff

File doc-fixes-r8995-2.diff, 2.6 KB (added by Ramiro Morales, 16 years ago)
  • docs/ref/models/querysets.txt

    QuerySet API reference  
    77.. currentmodule:: django.db.models
    88
    99This 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.
     10material presented in the :ref:`model <topics-db-models>` and :ref:`database
     11query <topics-db-queries>` guides, so you'll probably want to read and
     12understand those documents before reading this one.
    1313
    1414Throughout this reference we'll use the :ref:`example weblog models
    1515<queryset-model-example>` presented in the :ref:`database query guide
    respect to case-sensitivity, Django will  
    192192respect to case-sensitivity, Django will order results however your database
    193193backend normally orders them.
    194194
     195``reverse()``
     196~~~~~~~~~~~~~
     197
     198.. versionadded:: 1.0
     199
     200Use the ``reverse()`` method to reverse the order in which a queryset's
     201elements are returned. Calling ``reverse()`` a second time restores the
     202ordering back to the normal direction.
     203
     204To retrieve the ''last'' five items in a queryset, you could do this::
     205
     206    my_queryset.reverse()[:5]
     207
     208Note that this is not quite the same as slicing from the end of a sequence in
     209Python. The above example will return the last item first, then the
     210penultimate 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
     212that mode of access (slicing from the end), because it's not possible to do it
     213efficiently in SQL.
     214
    195215Also, note that ``reverse()`` should generally only be called on a
    196216``QuerySet`` which has a defined ordering (e.g., when querying against
    197217a model which defines a default ordering, or when using
    a model which defines a default ordering  
    199219``QuerySet``, calling ``reverse()`` on it has no real effect (the
    200220ordering was undefined prior to calling ``reverse()``, and will remain
    201221undefined afterward).
    202 
    203222
    204223``distinct()``
    205224~~~~~~~~~~~~~~
    Examples::  
    392411
    393412    >>> Entry.objects.none()
    394413    []
     414
     415``all()``
     416~~~~~~~~~~
     417
     418.. versionadded:: 1.0
     419
     420Returns a ''copy'' of the current ``QuerySet`` (or ``QuerySet`` subclass you
     421pass in). This can be useful in some situations where you might want to pass
     422in either a model manager or a ``QuerySet`` and do further filtering on the
     423result. You can safely call ``all()`` on either object and then you'll
     424definitely have a ``QuerySet`` to work with.
    395425
    396426.. _select-related:
    397427
Back to Top