Re: Slicing [-1] on objects.all()

2006-05-26 Thread Luke Plant
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, > > to

Re: Slicing [-1] on objects.all()

2006-05-26 Thread Luke Plant
Jay Parlar wrote: > Maybe a note should go into the db_api docs about -1 not working? I > did look at those docs before sending my original message, and didn't > see anything about that. I think it should throw an exception saying that negative indices are not supported (and even include a hint

Re: Slicing [-1] on objects.all()

2006-05-25 Thread Jan Claeys
Op do, 25-05-2006 te 11:28 -0400, schreef Ian Maurer: > Django's QuerySet handles slicing through the LIMIT and OFFSET clauses > of the database. Since the clauses cannot handle python's "negative > indexing" scheme, you have 2 choices: [...] > 2. Use an order_by method to set the reverse order an

Re: Slicing [-1] on objects.all()

2006-05-25 Thread Jay Parlar
On 5/25/06, Ian Maurer <[EMAIL PROTECTED]> wrote: > > Django's QuerySet handles slicing through the LIMIT and OFFSET clauses > of the database. Since the clauses cannot handle python's "negative > indexing" scheme, you have 2 choices: > > 1. Do the actual evaluation, by converting to a list and th

Re: Slicing [-1] on objects.all()

2006-05-25 Thread Ian Maurer
Django's QuerySet handles slicing through the LIMIT and OFFSET clauses of the database. Since the clauses cannot handle python's "negative indexing" scheme, you have 2 choices: 1. Do the actual evaluation, by converting to a list and then doing your slice: list(Foo.objects.all())[-1] 2. Use