user2935897
user2935897

Reputation: 117

Setting Permissions to a group/User in Django

I've a group in auth_group table. I need to set permissions to a group. There are set of permissions in auth_permission table. Now If I need to map all the permissions to a group, do I need to add different rows for each permissions, or can it be done by adding all the permissions as a string of 1 & 0?

For eg:- Should I add entries in the table as

id,group_id,permission_id

1,1,1
2,1,2
3,1,3
4,1,4

or is there any way, I can add all the permissions in one string, such as 1234, each digit signifying a permission_id?

Upvotes: 4

Views: 2086

Answers (1)

ndpu
ndpu

Reputation: 22571

You can get all permissions from Permission model and add them to a group:

from django.contrib.auth.models import Group, Permission

permissions = Permission.objects.all()
auth_group = Group.objects.get(...)
auth_group.permissions.add(*permissions)

Upvotes: 6

Related Questions