标签:framework serial param cts 数据 obj filter 序列 view
根据商品分类categroy_id查询数据库(分页,排序,序列化) 返回给前端
自定义分页类
from rest_framework.pagination import PageNumberPagination class StandardResultsSetPagination(PageNumberPagination): page_size = 2 page_size_query_param = ‘page_size‘ max_page_size = 20
在配置文件中指定分页类
REST_FRAMEWORK = { ... # 分页 ‘DEFAULT_PAGINATION_CLASS‘: ‘meiduo_mall.utils.pagination.StandardResultsSetPagination‘, }
在goods/views.py实现sku列表视图
from rest_framework.filters import OrderingFilter class SKUListView(ListAPIView): """ sku列表数据 """ serializer_class = SKUSerializer filter_backends = (OrderingFilter,) ordering_fields = (‘create_time‘, ‘price‘, ‘sales‘) def get_queryset(self): category_id = self.kwargs[‘category_id‘] return SKU.objects.filter(category_id=category_id, is_launched=True)
标签:framework serial param cts 数据 obj filter 序列 view
原文地址:https://www.cnblogs.com/whigym/p/10040813.html