1234567891011121314151617181920212223242526272829 |
- #coding=utf-8
- from rest_framework import pagination
- from rest_framework.response import Response
- import math
- class CustomPagination(pagination.PageNumberPagination):
- page_query_param = 'page'
- page_size_query_param = 'limit'
- page_size = 10
- def get_paginated_response(self, data):
- ps = self.get_page_size(self.request)
- # 底栏合计
- totalRow = {}
- if len(data) > 0 and 'totalRow' in data[-1:][0]:
- totalRow = data[-1:][0]
- data = data[:-1]
- return Response({
- 'code':0,
- 'showCount': ps,
- 'totalPage': math.ceil(self.page.paginator.count * 1.0 / ps),
- 'totalResult': self.page.paginator.count,
- 'currentPage': self.page.number,
- 'count': self.page.paginator.count,
- 'totalRow': totalRow,
- 'data': data
- })
|