goods/views.py
class GoodsListViewSet(viewsets.ModelViewSet): """ list: 商品列表 read: 商品详情 create: 增加商品 update: 更改商品 partial_update: 部分更改 delete: 删除商品 """ # 必须定义一个默认排序否则会报错 queryset = Goods.objects.all().order_by('id') # 分页 pagination_class = GoodsPagination serializer_class = GoodsSerializer # 过滤 filter_backends = (DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter) filter_class = GoodsFilters # 搜索 search_fields = ('name', 'goods_brief', 'goods_desc') # 排序 ordering_fields = ('sold_num', 'shop_price')