9个视图子类
# 9个视图子类
class BookListGenericAPIView(GenericAPIView, ListModelMixin):
queryset = Book.objects.all()
serializer_class = Bookserializers
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
class BookCreateGenericAPIView(GenericAPIView, CreateModelMixin):
queryset = Book.objects.all()
serializer_class = Bookserializers
def post(self, request):
return self.create(request)
class BookRetrieveGenericAPIView(GenericAPIView, RetrieveModelMixin):
queryset = Book.objects.all()
serializer_class = Bookserializers
def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs)
class BookUpdateGenericAPIView(GenericAPIView, UpdateModelMixin):
queryset = Book.objects.all()
serializer_class = Bookserializers
def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)
class BookDestroyGenericAPIView(GenericAPIView, DestroyModelMixin):
queryset = Book.objects.all()
serializer_class = Bookserializers
def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs)
class BookUpdateRetrieveDestroyGenericAPIView(GenericAPIView, DestroyModelMixin, RetrieveModelMixin, UpdateModelMixin):
queryset = Book.objects.all()
serializer_class = Bookserializers
def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs)
def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs)
def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)
class BookListCreateGenericAPIView(GenericAPIView, ListModelMixin, CreateModelMixin):
queryset = Book.objects.all()
serializer_class = Bookserializers
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)