10.[drf] 커스텀 퍼미션

퍼미션 커스텀

  • 보통 기본 퍼미션을 많이 사용하지만 커스텀을 해보겠습니다.

permissions.py

from rest_framework import permissions

class IsOwnerOrReadOnly(permissions.BasePermission):
    message = "You are not allowed to update or delete an article that does not belong to you"
    def has_object_permission(self, request, view, obj):
        if request.method in permissions.SAFE_METHODS:
            return True

        return obj.author == request.user