Irmantas Želionis
Irmantas Želionis

Reputation: 2324

How to check if object value in manytomany field?

How to check if value is in manytomany field? I am trying to do something like this:

if value in object1.followers:
    #BLA BLA BLA

But 'ManyRelatedManager' is not iterable. So what is correct way to do it?

Upvotes: 4

Views: 2737

Answers (1)

Joren
Joren

Reputation: 3297

You forgot the all():

if value in object1.followers.all():
    ...

Upvotes: 11

Related Questions