Created
February 21, 2022 17:09
-
-
Save xtornasol512/10b55ca897408972d45e5d0313dc41dd to your computer and use it in GitHub Desktop.
Add permissions to a group, using Django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Little snippet for looking for permissions and add them to a group """ | |
from django.contrib.auth.models import Group | |
from django.contrib.auth.models import Permission | |
from <your-model-folder>.models import <MODEL>, <MODEL-N> | |
gp = Group.objects.get(name="<GROUP_NAME>") | |
qs = Permission.objects.filter(codename__icontains="<FOLDER-NAME>") | |
for p in qs: | |
gp.permissions.add(p) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment