zoukankan      html  css  js  c++  java
  • cursor游标方式

    基本使用:

    -page=CursorPagination实例化产生对象
    -返回值=page.paginate_queryset(ret,request,self):ret是要分页的所有数据,
    -再序列化,序列化该返回值
    1
    2
    3
    四个参数:

    #每页显示的大小
    page.page_size=3
    #查询的key值
    page.cursor_query_param='cursor'
    # 按什么排序
    page.ordering='id'
    1
    2
    3
    4
    5
    6
    注意:get_paginated_response:调用这个方法返回的数据中会有总条数,上一页地址,下一页地址

    from rest_framework.pagination import CursorPagination
    class PublishView(APIView):
    def get(self, request, *args, **kwargs):
    ret = models.Publish.objects.all()
    # 实例化产生一个偏移分页对象
    page = CursorPagination()
    #三个参数:
    #每页显示的大小
    page.page_size=3
    #查询的key值
    page.cursor_query_param='cursor'
    # 按什么排序
    page.ordering='id'
    ret_page = page.paginate_queryset(ret, request, self)
    # 序列化
    pub_ser = serializer.PublishSerializers(ret_page, many=True)
    # 去setting中配置每页显示多少条
    return page.get_paginated_response(pub_ser.data)
    --------------------- 

  • 相关阅读:
    MYSQL索引
    Objective-C:KVO
    iOS UIKit:viewController之动画(5)
    iOS UIKit:viewController之Segues (4)
    iOS UIKit:viewController之Present (3)
    iOS UIKit:viewController之定义(2)
    iOS UIKit:viewController之层次结构(1)
    iOS UIKit:view
    iOS UIKit:App
    Objective-C:Block
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11284651.html
Copyright © 2011-2022 走看看