Friday, October 28, 2011

Comparing two ManyToMany fields for same entries

Hello,

I am building a model which shares a relation with another model
using a ManyToManyField. What I need to do, is find out which models
are on both on two seperate ManyToManyField lists. Here is a simple
example of what I am trying to do:

Person:
friends=ManyToManyField(self)

To find out this persons direct friends, Person.friends...
To find out which friends this Person shares in common with another
Person, ????

Person0:
Person1
Person6
Person3
Person8

Person1:
Person2
Person6

What would be the most optimized QuerySet to find out that both
Person0 and Person1 are both friends with Person6?

Is there a specific Django app perhaps that can ease develop of this
type of data relations between objects?

Thanks.

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