diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-05-06 03:44:14 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-05-06 03:44:14 +0000 |
| commit | 862328a98f63febb501a6ebb5d09c2db0574b53d (patch) | |
| tree | 44bbb687e9358d4154621563f489ccd7f66b9bbc /docs/db-api.txt | |
| parent | 4bc4aa2fa6d9fd6eabc8f03f888c9ae88a2d1cbe (diff) | |
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
Diffstat (limited to 'docs/db-api.txt')
| -rw-r--r-- | docs/db-api.txt | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/docs/db-api.txt b/docs/db-api.txt index a25a374bbc..c207812081 100644 --- a/docs/db-api.txt +++ b/docs/db-api.txt @@ -335,11 +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``), slice the ``QuerySet`` to ``[:1]`` and -call ``get()`` on that. For example, this returns the first ``Entry`` in the -database, after ordering entries alphabetically by headline:: +(e.g. ``SELECT foo FROM bar LIMIT 1``), using 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')[:1].get() + Entry.objects.order_by('headline')[0] + +This is 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. QuerySet methods that return new QuerySets ------------------------------------------ |
