Skip to content

Commit 862328a

Browse files
Simplified example in 'Limiting QuerySets' section of docs/db-api.txt.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2855 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 4bc4aa2 commit 862328a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

docs/db-api.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,18 @@ return a list of every *second* object of the first 10::
335335
Entry.objects.all()[:10:2]
336336

337337
To retrieve a *single* object rather than a list
338-
(e.g. ``SELECT foo FROM bar LIMIT 1``), slice the ``QuerySet`` to ``[:1]`` and
339-
call ``get()`` on that. For example, this returns the first ``Entry`` in the
340-
database, after ordering entries alphabetically by headline::
338+
(e.g. ``SELECT foo FROM bar LIMIT 1``), using a simple index instead of a
339+
slice. For example, this returns the first ``Entry`` in the database, after
340+
ordering entries alphabetically by headline::
341341

342-
Entry.objects.order_by('headline')[:1].get()
342+
Entry.objects.order_by('headline')[0]
343+
344+
This is equivalent to::
345+
346+
Entry.objects.order_by('headline')[0:1].get()
347+
348+
Note that either of these two examples will raise ``DoesNotExist`` if no
349+
objects match the given criteria.
343350

344351
QuerySet methods that return new QuerySets
345352
------------------------------------------

0 commit comments

Comments
 (0)