On Friday 26 May 2006 03:31, Jan Claeys wrote:
> > 2. Use an order_by method to set the reverse order and then get the
> > first item, use a minus sign to denote DESC order:
> >
> > Foo.objects.order_by("-column")[0]
> >
> > The second option is FAR superior. The first solution is, IMO,
> > totally unacceptable since it retrieves all of the records just to
> > access one row.
>
> Quick thought: can't the QuerySet do that itself then?
No, inverting the ordering does not, strictly speaking, reverse the
result set, since 2 or more items can have the same sort order, in
which case their relative ordering (in the list returned by the DB) is
undefined. Foo.objects.order_by("column")[0] is not necessarily the
same as list(Foo.objects.order_by("-column"))[-1], so it would be
incorrect for a QuerySet to assume that.
Luke
--
The early bird gets the worm, but the second mouse gets the cheese.
--Steven Wright
Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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-users
-~----------~----~----~----~------~----~------~--~---