Created
March 6, 2023 08:12
-
-
Save aimedey19/69916b2c164359bce70f0d1327470421 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Creating and getting the group | |
teacher_group, created = Group.objects.get_or_create(name='Teacher') | |
# Setting permissions | |
# Granting all access on CourseCategory Model | |
content_type_course_category = ContentType.objects.get_for_model(CourseCategory) | |
# Granting all access on Course Model | |
content_type_course = ContentType.objects.get_for_model(Course) | |
content_type_query = Q(content_type=content_type_course_category) | Q(content_type=content_type_course) | |
code_name_query = Q(codename='delete_course') | Q(codename='delete_coursecategory') | |
permissions = Permission.objects.filter(content_type_query).exclude(code_name_query) | |
teacher_group.permissions.set(permissions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment