May 2018
Beginner to intermediate
526 pages
11h 57m
English
We want students to be able to access the contents of the courses they are enrolled in. Only students enrolled in a course should be able to access its contents. The best way to do this is with a custom permission class. Django provides a BasePermission class that allows you to define the following methods:
These methods should return True to grant access or False otherwise. Create a new file inside the courses/api/ directory and name it permissions.py. Add the following code to it:
from rest_framework.permissions import BasePermissionclass IsEnrolled(BasePermission): def has_object_permission(self, request, ...
Read now
Unlock full access