[Django]-Django check if object in ManyToMany field

109👍

if user.partner_set.filter(slug=requested_slug).exists():
     # do some private stuff

7👍

If we just need to know whether a user object is associated to a partner object, we could just do the following (as in this answer):

if user in partner.user.all():
    #do something
👤Anupam

Leave a comment