December 2018
Intermediate to advanced
500 pages
12h 33m
English
Create a new Python file named customized_permissions.py within the games_service/games folder and enter the following code that declares the new IsOwnerOrReadOnly class. The code file for the sample is included in the restful_python_2_07_04 folder, in the Django01/games-service/games/customized_permissions.py file:
from rest_framework import permissions
class IsOwnerOrReadOnly(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
if request.method in permissions.SAFE_METHODS:
return True
else:
return obj.owner == request.user
The rest_framework.permissions.BasePermission class is the base class from which all permission classes should inherit. ...
Read now
Unlock full access