On Fri, 22 Apr 2011 07:02:22 +0300, Oleg Lomaka <oleg.lom...@gmail.com> wrote: > Blog.objects.filter(entry__pub_date__lte=date(2011, 4, 1), > entry__headline__contains='Easter > ').latest('pub_date') > > Or > > Blog.objects.filter(entry__pub_date__lte=date(2011, 4, 1), > entry__headline__contains='Easter > ').order_by('-pub_date')[0]
No, that's not what Carsten asked for: > On Thu, Apr 21, 2011 at 10:25 PM, Carsten Fuchs > <carstenfu...@t-online.de>wrote: > > What I'm wondering about is how I can find blogs whose *most recent* entry > > before or at April 1st has the word "Easter" in the headline. Actually, it's quite a mess in SQL, and I'd probably rather check the condition in python on the client, just for clarity, if the performance is reasonable. In SQL, it's something along SELECT ... FROM blog JOIN entry e1 on e1.entry_id = blog.id AND e1.pub_date <= ... AND e1.headline LIKE "%Easter%" AND NOT exists ( SELECT id from entry e2 WHERE e2.entry_id = blog.id AND e2.pub_date <= ... AND e2.pub_date > e1.pub_date ) Well ... even after 5 years with Django, I still think more in SQL than in Django ORM. Does anyone know how to that in the ORM? Kind regards Michael -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.