Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django group with permission

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

django group permissions method

group.permissions.set([permission_list])
group.permissions.add(permission, permission, ...)
group.permissions.remove(permission, permission, ...)
group.permissions.clear()
Comment

PREVIOUS NEXT
Code Example
Python :: how to insert item at specifc index python 
Python :: how to split a string with newline in python 
Python :: random python range 
Python :: views.py django 
Python :: pyqt5 qcombobox get selected item 
Python :: max value indices 
Python :: python bubble sort 
Python :: python first three characters of string 
Python :: AttributeError: ‘numpy.ndarray’ object has no attribute ‘append’ 
Python :: initialize a 2d list python 
Python :: python calculator file size to megabytes 
Python :: generate random int python 
Python :: beautiful soap python get the link online 
Python :: scikit learn train test split 
Python :: at=error code=h10 desc= app crashed python flask 
Python :: delete rows in a table that are present in another table pandas 
Python :: oserror: invalid cross-device link 
Python :: check auth user django 
Python :: Filter with List Comprehension 
Python :: append two list of number to one python 
Python :: how to convert numpy array to cv2 image 
Python :: multiple bars barchart matplotlib 
Python :: make int into string python 
Python :: get source code selenium python 
Python :: compare two datetime in python 
Python :: higlight words in python 
Python :: square a number in python 
Python :: serialize keras model 
Python :: python object of type set is not json serializable 
Python :: plt.hist using bins 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =