[Answered ]-How to filter with manytomany field?


If i understand your question right you have a specific site and your trying to filter by that site. Then you should filter like this:

site = Site.objects.get(pk=1)

mymodel_for_site = MyModel.objects.filter(field1=thing, sites=site)

This should get all the MyModel instances for a particular site



Try to make it via MyModel object, i.e.:

object = MyModel.objects.get(field1=thing)
qs = object.sites.all()

Check django docs


Leave a comment