parent
c1ae3201ea
commit
e275862948
2 changed files with 36 additions and 1 deletions
@ -0,0 +1,33 @@ |
||||
from rest_framework import mixins |
||||
from rest_framework import generics |
||||
|
||||
from apps.goods.models import Goods |
||||
from apps.goods.serializers import GoodsSerializers |
||||
|
||||
|
||||
class GoodsMixin(mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView): |
||||
queryset = Goods.objects.all() |
||||
serializer_class = GoodsSerializers |
||||
|
||||
# GoodsSerializers(queryset, many=True) |
||||
|
||||
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 GoodsDetailMixin(mixins.RetrieveModelMixin, mixins.UpdateModelMixin, mixins.DestroyModelMixin, |
||||
generics.GenericAPIView): |
||||
queryset = Goods.objects.all() |
||||
serializer_class = GoodsSerializers |
||||
|
||||
def get(self, request, *args, **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) |
Loading…
Reference in new issue