Friday, September 9, 2011

Re: Trouble expressing a query in the ORM

On Sep 9, 2011, at 6:28 AM, Pewpewarrows wrote:

> prop_dates = Target.objects.annotate(latest_property=Max('property__export_date')).values_list('latest_property', flat=True)
> properties = Property.objects.filter(export_date__in=prop_dates)

Note that if prop_dates has more than 10-15 entries, it's going to perform badly (at least on PostgreSQL, and almost certainly on MySQL too). I think this particular situation is definitely a .raw() opportunity.

--
-- Christophe Pettus
xof@thebuild.com

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment