def has_role(user_roles, searched_role): found = False for i in user_roles: if i.name == searched_role: found = True return found