He is expecting to fetch a single term. I think that's what get() does if the
particular I'd is known and you would have written your code as this:
Foo.objects.get(id=1000)
However, if you don't know like I'm presuming, you do:
Foo.objects.all().order_by('-pk')[0]
Tom, thanks.
Sent from my BlackBerry wireless device from MTN
-----Original Message-----
From: Tom Evans <[email protected]>
Sender: [email protected]
Date: Wed, 23 Feb 2011 13:04:29
To: <[email protected]>
Reply-To: [email protected]
Subject: Re: Querysets: returning a single item with the greatest id.
On Wed, Feb 23, 2011 at 12:57 PM, Sithembewena Lloyd Dube
<[email protected]> wrote:
> Hi everyone,
>
> How would one fetch a single item with the largest id (or most recent date
> of creation) via the database API?
>
> --
> Regards,
> Sithembewena Lloyd Dube
>
Foo.objects.all().order_by('-pk')[0] ?
Cheers
Tom
--
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.
--
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.