[Solved]-How to retrieve all permissions assigned to a group in Django

14👍

The Group model has a ManyToMany relationship with the Permission model, so you can do this

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

9👍

To get all permissions in all groups the current user belongs to use this:

all_permissions_in_groups = user.get_group_permissions()

To get all permissions related to a user including ones that are not in any group do this:

all_permissions = user.get_all_permissions()

For more details see Django documentation

👤7guyo

1👍

If you have the name of the group, one way is:

from django.contrib.auth.models import Group
group_name = "test"

group_permissions = Group.objects.get(name=group_name).permissions.all()

Leave a comment