Complete the code to define a custom permission class in Django REST Framework.
from rest_framework.permissions import [1] class IsOwnerPermission([1]): def has_object_permission(self, request, view, obj): return obj.owner == request.user
The custom permission class should inherit from BasePermission to define custom logic.
Complete the code to check if the user is the owner of the object in the permission method.
def has_object_permission(self, request, view, obj): return obj.[1] == request.user
The permission checks if the owner attribute of the object matches the current user.
Fix the error in the permission class by completing the missing import statement.
from rest_framework.permissions import [1], SAFE_METHODS class IsAdminOrReadOnly([1]): def has_permission(self, request, view): if request.method in SAFE_METHODS: return True return request.user and request.user.is_staff
The class should inherit from BasePermission and import it to define custom permission logic.
Fill both blanks to correctly apply the custom permission class to a Django REST Framework view.
from rest_framework.views import APIView from .permissions import [1] class MyView(APIView): permission_classes = [[2]]
The custom permission IsOwnerPermission is imported and applied in the permission_classes list.
Fill all three blanks to create a custom permission that allows safe methods for everyone but restricts other methods to the object's owner.
from rest_framework.permissions import BasePermission, SAFE_METHODS class [1](BasePermission): def has_object_permission(self, request, view, obj): if request.method in [2]: return True return obj.[3] == request.user
The class IsOwnerOrReadOnly allows safe methods for all and restricts other methods to the object's owner.