Django: get all permissions on template separated by groups

Viewed 166

I have an admin site, I want to edit and add roles to it.

It looks like this enter image description here

I can get all the permissions using the POST method by calling every name but I have many permissions and groups.

But by using that I can only save one group at a time.

Is there a way to get the permissions separated by groups when the save button was clicked?

For example:

{'Super Admin':['permision1','permision2'], 'Admin':['permision1'], 'Subscription Manager':['permision2]}
1 Answers

You can fetch the items with the permissions with:

from django.contrib.auth.models import Group

{
    group.name: [perm.name for perm in group.permissions.all()]
    for group in Group.objects.prefetch_related('permissions')
}
Related