How set permissions for create action in rest_framework
<p>I want to set perissions for the create action (post). And I dont know hot to do it.</p>

<p>This is my code:</p>

<p>In permissions.py</p>

<pre><code>class IsAdmin(permissions.BasePermission):
    def has_object_permission(self, request, view, category):
        if request.user.role == "admin":
            return request.user.role == "admin"
        return False
</code></pre>

<p>In view</p>

<p>class CategoryViewSet(viewsets.ModelViewSet):</p>

<pre><code>queryset = Category.objects.all()
serializer_class = CategorySerializer

def get_permissions(self):
    if self.request.method in permissions.SAFE_METHODS:
        return (permissions.DjangoModelPermissions(),)
    return (permissions.IsAuthenticated(), IsAdmin(),)
</code></pre>

<p>Just set the <code>permission_classes</code> on the viewset directly:</p>

<pre><code>class CategoryViewSet(viewsets.ModelViewSet):

    queryset = Category.objects.all()
    serializer_class = CategorySerializer
    permission_classes = [IsAccountAdminOrReadOnly]
</code></pre>

python django rest django-rest-framework