4

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?

user2935897
  • 117
  • 7

1 Answers1

6

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)
ndpu
  • 22,225
  • 6
  • 54
  • 69
  • Thanks. But how will that be represented in mysql tables? As in, the structure that I mentioned above- table-like or a string wise? – user2935897 Dec 23 '13 at 19:14
  • @user2935897 all permissions ids will be added to table auth_group_permissions (id,group_id,permission_id) – ndpu Dec 23 '13 at 19:20