On Feb 21, 7:27 pm, 3xM <[email protected]> wrote: > I've got 2 models: > > ---- > class Person(models.Model): > ... > > class Project(models.Model): > ... > persons = models.ManyToManyField(Person) > ---- > > Now, how do I lookup Projects including person_a and person_b? > > I've tried chaining filters like this, but that won't work (returning > no results): > > Project.objects.filter(persons__id=person_a.id).filter > (persons__id.person_b.id) > > Maybe I missed something, but I've read the documentation several > times now, without luck. > > Do I have to write the SQL myself? > > -- > > Best regards, Mikkel
No need for custom SQL here. This might work: Project.objects.filter(persons=person_a, persons=person_b) Or you could probably do it with Q objects: Project.objects.filter(Q(persons=person_a) & Q(persons=person_b)) -- DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

