You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
11 lines
327 B
11 lines
327 B
2 years ago
|
from rest_framework.permissions import BasePermission, SAFE_METHODS
|
||
|
|
||
|
|
||
|
class IsSelfOrReadOnly(BasePermission):
|
||
|
|
||
|
def has_object_permission(self, request, view, obj):
|
||
|
if request.method in SAFE_METHODS:
|
||
|
return True
|
||
|
"""确保非安全方法只能由本人操作"""
|
||
|
return obj == request.user
|