Answer the question
In order to leave comments, you need to log in
Django ManyToMany relation - how to select by AND?
Hello.
Perhaps this will seem banal to someone, but there is the following problem:
There is a model:
class Room(models.Model):
users = models.ManyToManyField(User, related_name='speakers')
....
SELECT * FROM (
SELECT messages_rooms_users.room_id, COUNT(messages_rooms_users.room_id) as ctx from messages_rooms_users
WHERE
messages_rooms_users.user_id in (__users_id_list__)
GROUP BY messages_rooms_users.room_id) as subq
WHERE subq.ctx = 2
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question