123456789101112131415161718192021 |
- from rest_framework_api_key.permissions import BaseHasAPIKey
- from .models import APIKey
- from rest_framework import permissions
- class HasAPIKey(BaseHasAPIKey):
- model = APIKey
- class HAsKeyPermissionn(permissions.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):
- print(request)
- if request.method in permissions.SAFE_METHODS:
- return True
- # Instance must have an attribute named `owner`.
- return obj.owner == request.user
|