diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-23 01:35:34 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-23 01:35:34 +0000 |
| commit | 6ad9c684aa23c62710047f94b8febc681cc30282 (patch) | |
| tree | 8f4642ed94ecadfcd2790d6f9183f03ab0feb966 /docs/db-api.txt | |
| parent | 7355fa6b728357a3e7257fbe1175d68a0d7e2ec1 (diff) | |
queryset-refactor: Implemented the reverse() method on querysets.
Refs #5012.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7148 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/db-api.txt')
| -rw-r--r-- | docs/db-api.txt | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/docs/db-api.txt b/docs/db-api.txt index d96541d58b..61bfd31882 100644 --- a/docs/db-api.txt +++ b/docs/db-api.txt @@ -554,6 +554,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. +``reverse()`` +~~~~~~~~~~~~~ + +**New in Django development version** + +If you want to reverse the order in which a queryset's elements are returned, +you can use the ``reverse()`` method. 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), since it is not possible to do it +efficiently in SQL. + ``distinct()`` ~~~~~~~~~~~~~~ |
