Check if Django Group has Permission

I am developing a Django website where I can create groups, where permissions can be assigned. I can also assign groups to users. There is a simple way to check if a user has a permission:


What I want to know is if there is a simple way to check if a specific group has a permission (without involving the user at all)?

You can do something like this:

for group in Group.objects.all():
    permissions = group.permissions.all()
    # do something with the permissions

Or, a better way would be:

group_ids = Group.objects.all().values_list('id', flat=True)  Permission.objects.filter(group__id__in=group_ids)

This link may be able to help you further.

Back to Top