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>Already, I have solved it, just i've change in my permissions.py file, the method:</p>

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

<p>for this method:</p>

<pre><code>    def has_permission(self, request, view):
    if request.user.role == "admin":
        return request.user.role == "admin"
    return False
</code></pre>

<p>It's Simple, i complicate too much</p>

python django rest django-rest-framework