Ticket #9000: doc-fixes-r8995-2.diff
File doc-fixes-r8995-2.diff, 2.6 KB (added by , 16 years ago) |
---|
-
docs/ref/models/querysets.txt
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 query11 <topics-db-queries>` guides, so you'll probably want to read and understand12 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 … … respect to case-sensitivity, Django will 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 … … a model which defines a default ordering 199 219 ``QuerySet``, calling ``reverse()`` on it has no real effect (the 200 220 ordering was undefined prior to calling ``reverse()``, and will remain 201 221 undefined afterward). 202 203 222 204 223 ``distinct()`` 205 224 ~~~~~~~~~~~~~~ … … Examples:: 392 411 393 412 >>> Entry.objects.none() 394 413 [] 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. 395 425 396 426 .. _select-related: 397 427