bennylope / django-organizations

:couple: Multi-user accounts for Django projects
http://django-organizations.readthedocs.org/
BSD 2-Clause "Simplified" License
1.31k stars 212 forks source link

Quick way to test if a User (not OrganisationUser) is a member of Organisation? #213

Closed asencis closed 3 years ago

asencis commented 3 years ago

As the title suggests, is there a way to test if a User is a member of any Organisation?

bennylope commented 3 years ago

If you're using the default models, any of the following ought to work:

Organization.objects.filter(users=user).exists()
OrganizationUser.objects.filter(user=user).exists()
user.organization_users.all().exists()  # use the reverse relation