Hmm ... I may or may not have answered your question.

On Tue, 2008-04-08 at 08:32 +1000, Malcolm Tredinnick wrote:
> 
> On Mon, 2008-04-07 at 15:29 -0700, [EMAIL PROTECTED] wrote:
> > # Note that you can't use 'offset' without 'limit' (on some dbs), so
> > this doesn't work:
> > >>> Article.objects.all()[2:]
> > Traceback (most recent call last):
> >     ...
> > AssertionError: 'offset' is not allowed without 'limit'

This isn't an example of retrieving "the last X". It's an example of
retrieving "all but the first 2". The way to do that is to convert the
queryset to a list and then slice.

        list(Article.objects.all())[2:]
        
That way, the slicing happens at the Python level, not the database
level.

> > I want to get X last entries from a DB like in example above. How can
> > I specify a "limit" - or what is the easiest way to get X last
> > objects ? I'm using MySQL, and pre0.97
> 
> Order your queryset in the opposite order to what it would normally be
> and then get the first X entries from that list. Soon there will be a
> reverse() method on querysets to do this "order in the opposite
> direction" for you, but for now, just do it manually.

This is correct if you really do want "the last X" for some known value
of X.

Regards,
Malcolm

-- 
Honk if you love peace and quiet. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to