Answer the question
In order to leave comments, you need to log in
How to set permissions on ListCreateAPIView?
Hi I have a class:
class PostList(generics.ListCreateAPIView):
permission_classes = (permissions.IsAuthenticated,)
model = Post
queryset = Post.objects.all()
serializer_class = PostSerializer
url(r'^posts/$', views.PostList.as_view(), name='post-list'),
Answer the question
In order to leave comments, you need to log in
Like this:
class PostList(generics.ListCreateAPIView):
def get_permissions(self):
if self.request.method == 'GET':
perms = [GetPermission]
else:
perms = [NotGetPermission]
return [p() for p in perms]
It is clear that the solution does not shine with beauty, it is, as they say, a low level. But this principle will be the basis of all improvements.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question