B
B
bbquite2021-09-08 09:57:24
Django
bbquite, 2021-09-08 09:57:24

How to get an object by exact occurrence in ManyToManyField?

There is a model:

class Dialog(models.Model):
    is_active = models.BooleanField(
        verbose_name='Активность', blank=False, default=True)
    members = models.ManyToManyField(
        "users.User", verbose_name='Участники',
        related_name='dialogues')


How can I get an object by exact occurrence of participants?
if you use members__in[...], it finds dialogs in which only one of the participants is in the list

I also tried using Q
dialog = Dialog.objects.filter( Q(members__in=[self.request.user,]) & Q(members__in=[another,]))
, also finds extra

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question