Permalink
Browse files

require auth to edit

  • Loading branch information...
junkboy0315 committed Feb 11, 2019
1 parent 75989a5 commit b4bf18f7124ed7cac509851a41b6f4a83ee0614d
Showing with 4 additions and 1 deletion.
  1. +4 −1 tutorial/snippets/views.py
@@ -1,4 +1,4 @@
from rest_framework import generics
from rest_framework import generics, permissions
from snippets.models import Snippet
from snippets.serializers import SnippetSerializer

@@ -10,14 +10,17 @@ class SnippetList(generics.ListCreateAPIView):
"""
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)

# 新規作成(POST)時にはユーザ情報を一緒に保存する
def perform_create(self, serializer):
serializer.save(owner=self.request.user)


class SnippetDetail(generics.RetrieveUpdateDestroyAPIView):
"""
単一のスニペットの、取得・更新・削除を行う。
"""
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)

0 comments on commit b4bf18f

Please sign in to comment.