permissions

This commit is contained in:
Pratyush Desai 2022-01-08 05:18:12 +05:30
parent 3632f27583
commit 18b063713e
Signed by: pratyush
GPG Key ID: DBA5BB7505946FAD

View File

@ -2,11 +2,12 @@ from django.contrib.auth.models import User
from .models import Snippet from .models import Snippet
from .serializers import SnippetSerializer, UserSerializer from .serializers import SnippetSerializer, UserSerializer
from rest_framework import generics from rest_framework import generics, permissions
class SnippetList(generics.ListCreateAPIView): class SnippetList(generics.ListCreateAPIView):
queryset = Snippet.objects.all() queryset = Snippet.objects.all()
serializer_class = SnippetSerializer serializer_class = SnippetSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
def perform_create(self, serializer): def perform_create(self, serializer):
serializer.save(owner=self.request.user) serializer.save(owner=self.request.user)
@ -15,6 +16,7 @@ class SnippetList(generics.ListCreateAPIView):
class SnippetDetail(generics.RetrieveUpdateDestroyAPIView): class SnippetDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Snippet.objects.all() queryset = Snippet.objects.all()
serializer_class = SnippetSerializer serializer_class = SnippetSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
class UserList(generics.ListAPIView): class UserList(generics.ListAPIView):
queryset = User.objects.all() queryset = User.objects.all()