Permalink
Browse files

generic view

  • Loading branch information...
junkboy0315 committed Feb 8, 2019
1 parent 32e625b commit ea640baa9ca36d8724ae0c5c9da08899f4109204
Showing with 3 additions and 23 deletions.
  1. +3 −23 tutorial/snippets/views.py
@@ -1,40 +1,20 @@
from rest_framework import generics, mixins, status
from rest_framework import generics
from snippets.models import Snippet
from snippets.serializers import SnippetSerializer


class SnippetList(mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView):
class SnippetList(generics.ListCreateAPIView):
"""
- 全ての snippets を表示する。
- 新しい snippet を作成する
"""
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer

def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)


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

def get(self, request, *args, **kwargs): # なお、pkはkwargsとして渡ってくる
return self.retrieve(request, *args, **kwargs)

def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)

def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs)

0 comments on commit ea640ba

Please sign in to comment.