#自己序列化
通过Django的View model_to_dict方法 serializers JsonResponse来完成序列化
"""
商品列表页, 分页, 搜索, 过滤, 排序
"""
# throttle_classes = (UserRateThrottle, )
queryset = Goods.objects.all()
serializer_class = GoodsSerializer
pagination_class = GoodsPagination
# authentication_classes = (TokenAuthentication, )
filter_backends = (DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter)
filter_class = GoodsFilter
search_fields = ('name', 'goods_brief', 'goods_desc')
通过Django的View model_to_dict方法 serializers JsonResponse来完成序列化
通过 django-rest-framework
"""
商品列表页, 分页, 搜索, 过滤, 排序
"""
# throttle_classes = (UserRateThrottle, )
queryset = Goods.objects.all()
serializer_class = GoodsSerializer
pagination_class = GoodsPagination
# authentication_classes = (TokenAuthentication, )
filter_backends = (DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter)
filter_class = GoodsFilter
search_fields = ('name', 'goods_brief', 'goods_desc')
ordering_fields = ('sold_num', 'shop_price')
很是方便 商品列表页, 分页, 搜索, 过滤, 排序 不需要太多的代码
Viewset组合使用
#继承关系 绑定urls
GenericViewSet(viewset) -drf
GenericAPIView -drf
APIView -drf
View -django
Mixin
CreateModelMixin
ListModelMixin
RetriveModelMixin
UpdateModeMixin
DestroyModelMixin