Answer the question
In order to leave comments, you need to log in
How to create a filter from ManyToMany and contains in Django?
I have these models:
class Model1(models.Model):
...
class Model2(models.Model):
m2m_field = models.ManyToManyField(Model1)
m1 = Model1.object.get(...) #он просто у меня есть
m2 = Model2.objects.all()
x = m2.filter(m2m_field__contains=m1)
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