Created
June 5, 2018 20:37
-
-
Save theparadoxer02/20c83757f7ab2fe7927c3360b0740a01 to your computer and use it in GitHub Desktop.
Add Permission to Group user using Django shell
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
from django.contrib.auth.models import Group, Permission | |
from django.contrib.contenttypes.models import ContentType | |
from users.models import User | |
new_group, created = Group.objects.get_or_create(name ='new_group') | |
# Code to add permission to group ??? | |
ct = ContentType.objects.get_for_model(User) | |
# Now what - Say I want to add 'Can go Haridwar' permission to level0? | |
permission = Permission.objects.create(codename ='can_go_haridwar', name ='Can go to Haridwar', content_type = ct) | |
new_group.permissions.add(permission). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment