One day I'll stop posting in this thread. Really.

On Sat, 2009-03-07 at 12:03 +1100, Malcolm Tredinnick wrote:

> However, find things that are simultaneously in all those categories can
> be done without all the annotation nonsense I posted. Simply
> 
>         
> Publication.objects.filter(article=1).filter(article=2).filter(article=3)
>         
> It's a short loop to build up such a set dynamically. The difference
> between that (3 filter calls) and you Q-object version is described in
> the documentation:
> http://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-valued-relationships

I forgot to mention that this approach is probably only practical for a
small number of article instances. Each filter() adds a new table join,
so at some point the database will complain. Either literally, about too
many joins, or by taking ages to attempt to optimise and execute the
query.

For a large number of article instances, the annotation-based solution I
gave earlier is more appropriate.

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to