Skip to content

Commit

Permalink
Updated docs regarding QuerySet slicing and IndexError, in line with …
Browse files Browse the repository at this point in the history
…r2859

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2862 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
spookylukey committed May 6, 2006
1 parent df668ee commit 3c72a46
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/db-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,18 @@ return a list of every *second* object of the first 10::
Entry.objects.all()[:10:2]

To retrieve a *single* object rather than a list
(e.g. ``SELECT foo FROM bar LIMIT 1``), using a simple index instead of a
(e.g. ``SELECT foo FROM bar LIMIT 1``), use a simple index instead of a
slice. For example, this returns the first ``Entry`` in the database, after
ordering entries alphabetically by headline::

Entry.objects.order_by('headline')[0]

This is equivalent to::
This is roughly equivalent to::

Entry.objects.order_by('headline')[0:1].get()

Note that either of these two examples will raise ``DoesNotExist`` if no
objects match the given criteria.
Note, however, that the first of these will raise ``IndexError`` while the
second will raise ``DoesNotExist`` if no objects match the given criteria.

QuerySet methods that return new QuerySets
------------------------------------------
Expand Down

0 comments on commit 3c72a46

Please sign in to comment.