Re: Get latest item by many items in a queryset

2011-09-30 Thread Colin
Hmm this may work for me. if I add the time range to the latest_status it is close to what I want! Thanks a bunch On Sep 30, 9:47 am, Dmitry Kuznetsov wrote: > Something like this? > > backends = [backend1,backend2,backend3] > latest_status = Status.objects.filter(backend__in=backends).latest() >

Re: Get latest item by many items in a queryset

2011-09-30 Thread Colin
Thanks for the info guys! Is there any changes I could make to my model? Right now I have about 165k backends and a huge number of statuses. But they are small if you only grab the last 10 or so minutes of statuses. On Sep 30, 10:43 am, Tom Evans wrote: > On Fri, Sep 30, 2011 at 2:48 PM, John w

Re: Get latest item by many items in a queryset

2011-09-30 Thread Tom Evans
On Fri, Sep 30, 2011 at 2:48 PM, John wrote: > I believe that there is no real way for you to avoid having to perform > a query for each backend instance.  Even in raw SQL, I don't think > there is a way to do what you want - in postgres, for example, you > could not both order by the timestamp an

Re: Get latest item by many items in a queryset

2011-09-30 Thread John
That would still return a single value - the status update with the latest timestamp with one of those backends. On Sep 30, 9:47 am, Dmitry Kuznetsov wrote: > Something like this? > > backends = [backend1,backend2,backend3] > latest_status = Status.objects.filter(backend__in=backends).latest() >

Re: Get latest item by many items in a queryset

2011-09-30 Thread John
I believe that there is no real way for you to avoid having to perform a query for each backend instance. Even in raw SQL, I don't think there is a way to do what you want - in postgres, for example, you could not both order by the timestamp and get distinct values based on backend. However, ther

Re: Get latest item by many items in a queryset

2011-09-30 Thread Dmitry Kuznetsov
Something like this? backends = [backend1,backend2,backend3] latest_status = Status.objects.filter(backend__in=backends).latest() Regards, Dmitry On Sep 29, 7:36 pm, Colin wrote: > Hi Users, > > So I have a DB that has a list of backends and there properties and I > have a table that gets updat