let's say I have a model like
class Group:
users = ManyToMany(User, related_name='groups')
and I have groups with a different mixture of users
group1 = Group(users=[user1])
group2 = Group(users=[user1, user2])
group3 = Group(users=[user1, user2, user3])
How would I go about querying for groups only with user1 and user2?
I'd like to do something that's like Group.objects.filter(users=[user1, user2]) -> [group2]
but I'm getting
TypeError: Field 'id' expected a number but got [<User: user1>, <User: user2>].
if I do Group.objects.filter(user__in=[user1, user2].distinct('id')
it returns back all the groups [group1, group2, group3]
I know how to go through the User instance to get all of the user's groups but I specifically want to go through the Group model.
I imagine I may have to do some type of matching with the ORM... maybe a subquery?