On 5/5/06, Luke Plant <[EMAIL PROTECTED]> wrote:
> > +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:: +
> > +    Entry.objects.order_by('headline')[:1].get()
> > +
>
> Thanks for doing the corrections, but this has confused me -- you can do
> exactly the same by doing this:
>
>  Entry.objects.order_by('headline')[0]
>
> The only difference is in caching (the latter will get the item from the
> cache if it the original QuerySet has already been evaluated).

Good call! I've changed the docs. For some reason I was thinking a
simple slice would raise KeyError instead of DoesNotExist, but it does
indeed raise DoesNotExist properly.

These docs, aside from the tutorial, are really coming together. Keep
the corrections and improvements comin'!

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to