aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/django_application/files/django_add_permission_to_group.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/modules/django_application/files/django_add_permission_to_group.py b/modules/django_application/files/django_add_permission_to_group.py
index c5edc31c..4e5714f3 100644
--- a/modules/django_application/files/django_add_permission_to_group.py
+++ b/modules/django_application/files/django_add_permission_to_group.py
@@ -3,9 +3,18 @@ import sys
group_name = sys.argv[1]
permission = sys.argv[2]
-from django.contrib.auth.models import Group,Permission
+# as codename is not unique, we need to give the application name
+app = ''
+if len(sys.argv) > 3:
+ app = sys.argv[3]
+
+from django.contrib.auth.models import Group, Permission
g = Group.objects.get(name=group_name)
-p = Permission.objects.get(codename=permission)
+
+p = Permission.objects.filter(codename=permission)
+if app:
+ p = p.filter(content_type__app_label__exact=app)
+p = p[0]
g.permissions.add(p)
g.save()