[0]
Tom, thanks.
Sent from my BlackBerry wireless device from MTN
-Original Message-
From: Tom Evans
Sender: django-users@googlegroups.com
Date: Wed, 23 Feb 2011 13:04:29
To:
Reply-To: django-users@googlegroups.com
Subject: Re: Querysets: returning a single item with the greatest id.
On
Does latest()[0] work exactly as the original poster was looking for?
latest() works based on a date field, not the pk field (which *could*
return a result different than expected).
Tom's approach, explicitly ordering by pk, would work exactly as
desired.
On Feb 23, 6:08 am, Mike Ramirez wrote:
@Tom, thanks. I thought of ordering the QuerySet, but I was not sure whether
that would default to ASC or DESC - and I was not sure how to pass
parameters to influence this.
@Mike, thanks. That looks simpler to do.
On Wed, Feb 23, 2011 at 3:08 PM, Mike Ramirez wrote:
> On Wednesday, February 2
On Wednesday, February 23, 2011 05:04:29 am Tom Evans wrote:
> On Wed, Feb 23, 2011 at 12:57 PM, Sithembewena Lloyd Dube
>
> 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,
On Wed, Feb 23, 2011 at 12:57 PM, Sithembewena Lloyd Dube
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
--
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
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email t
6 matches
Mail list logo