On Mon, 2006-06-12 at 12:09 -0700, medhat wrote: > Hi, > > If you have a many-to-many field, let's say for example Employee and > Project, is there a way given an arbitrary list of projects to get they > employees who work on all projects? (i.e. each on of the employees in > the result must be working on *all* projects in the list) > > I am interested in doing this with one resultant Q object. I can do it > with multiple queries and then building the list in python.
Wow, deja vu. This came up a while back in a thread on this list [1] and we came up with a solution at the time. Subsequent to that, I realised the original solution was unnecessarily ugly and when I had to implement the same thing in a personal project last week, I decided to write up the solution as a series of blog posts. It's turning into a multi-part blog posting. The SQL "problem" is at [2] and a discussion of a solution is at [3]. Later today, I will write up how to use this effectively in Django, so if you can wait eight hours, it will be up. Or maybe just seeing the original thread or SQL query will give you the clues you need. [1] http://groups.google.com/group/django-users/browse_thread/thread/065ad54287e10bbd/8f410e522e003a9a [2] http://www.pointy-stick.com/blog/2006/06/12/sql-puzzle/ [3] http://www.pointy-stick.com/blog/2006/06/13/sql-puzzle-solution/ Best wishes, 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---