可以自定义权限的类,下面是拥有者权限的类
from rest_framework.permissions import BasePermission,SAFE_METHODS
class IsOwnerOrReadOnly(BasePermission):
"""
Object-level permission to only allow owners of an object to edit it.
Assumes the model instance has an `owner` attribute.
"""
def has_object_permission(self, request, view, obj):
# Read permissions are allowed to any request,
# so we'll always allow GET, HEAD or OPTIONS requests.