标签:定义 res obj list ram ref pre 字段 backend
from rest_framework.pagination import CursorPagination
class CarCursorPagination(CursorPagination):
# 默认一页的条数
page_size = 3
# 用户可以自定义选择一页的条数,但最多显示max_page_size设置的条数
page_size_query_param = 'page_size'
max_page_size = 5
# 默认排序规则:按pk从小到大排序,-pk表示从大到小排序
ordering = 'pk'
from rest_framework.viewsets import ModelViewSet
from . import models, serializer
from .paginations import CarCursorPagin
from rest_framework.filters import OrderingFilter
class CarModelViewSet(ModelViewSet):
queryset = models.Car.objects.filter(is_delete=False)
serializer_class = serializer.CarModelSerializer
pagination_class = CarCursorPagination
# filter_backends = [OrderingFilter]
1.采用默认排序访问,url链接:car/?cursor=加密串
2.结合视图类实现OrderingFilter自定义排序访问,url链接:car/?cursor=加密串&ordering=排序字段
标签:定义 res obj list ram ref pre 字段 backend
原文地址:https://www.cnblogs.com/863652104kai/p/11523643.html