12345678910111213141516171819202122232425262728 |
- #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):
- print(self.page_size_query_param)
- ps = self.get_page_size(self.request)
- print(2222222222, self.page.paginator.count)
- print(3333333, self.page.number)
- print(444444, ps)
- print(555555, len(data))
- 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,
- 'data': data
- })
|