Skip to content

Instantly share code, notes, and snippets.

@theparadoxer02
Created June 5, 2018 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theparadoxer02/20c83757f7ab2fe7927c3360b0740a01 to your computer and use it in GitHub Desktop.
Save theparadoxer02/20c83757f7ab2fe7927c3360b0740a01 to your computer and use it in GitHub Desktop.
Add Permission to Group user using Django shell
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