fox
fox

Reputation: 16546

Using filter on a manytomany through object

trying to gather a collection of objects:

set = [model1].objects.all().filter([model2]__in=[model3].[model2]_set)

but I get a

TypeError at [url]
'ManyRelatedManager' object is not iterable 

when I try to do this. Models 2 and 3 are related via a ManyToMany field in Model 2 through a fourth model that has both models as fields.

Any obvious workarounds?

Upvotes: 0

Views: 145

Answers (1)

armonge
armonge

Reputation: 3138

I believe your problem is in [model2]__in=[model3].[model2]_set the correct form would be

set = [model1].objects.all().filter([model2]__in=[model3].[model2]_set.all())

Upvotes: 2

Related Questions