Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

create django group

from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
from api.models import Project
new_group, created = Group.objects.get_or_create(name='new_group')
# Code to add permission to group ???
ct = ContentType.objects.get_for_model(Project)

# Now what - Say I want to add 'Can add project' permission to new_group?
permission = Permission.objects.create(codename='can_add_project',
                                   name='Can add project',
                                   content_type=ct)
new_group.permissions.add(permission)
Comment

PREVIOUS NEXT
Code Example
Python :: separate a string in python 
Python :: copy website python 
Python :: linspace python 
Python :: pywhatkit send message 
Python :: what is from_records in DataFrame() pandas in python? 
Python :: how to make a list using lambda function in python 
Python :: is python platform independent 
Python :: add new keys to a dictionary python 
Python :: pandas profile report python 
Python :: how to create a python script to automate software installation? 
Python :: for i 
Python :: split pandas row into multiple rows 
Python :: numpy convert true false to 0 1 
Python :: flask python use specified port 
Python :: arrange array in ascending order python 
Python :: get number of zero is a row pandas 
Python :: loop throughthe key and the values of a dict in python 
Python :: fromkeys in python 
Python :: how to send file using socket in python 
Python :: selenium open inspect 
Python :: numpy check if an array is all zero 
Python :: compare two dictionaries in python 
Python :: pandas df filter by time hour 
Python :: python replace double quotes with single quotes in string json loads 
Python :: declare empty array of complex type python 
Python :: django python base 64 decode 
Python :: how to get the first key of a dictionary in python 
Python :: random number generator in python 
Python :: takes 1 positional argument but 2 were given python 
Python :: run flask in debug mode 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =