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')

 

相关文章:

  • 2018-12-23
  • 2021-05-24
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2018-08-09
  • 2021-07-07
  • 2021-06-08
  • 2021-08-13
  • 2021-07-10
  • 2021-06-12
  • 2019-12-12
相关资源
相似解决方案