pagination.py 679 B

1234567891011121314151617181920212223
  1. #coding=utf-8
  2. from rest_framework import pagination
  3. from rest_framework.response import Response
  4. import math
  5. class CustomPagination(pagination.PageNumberPagination):
  6. page_query_param = 'page'
  7. page_size_query_param = 'limit'
  8. page_size = 10
  9. def get_paginated_response(self, data):
  10. ps = self.get_page_size(self.request)
  11. return Response({
  12. 'code':0,
  13. 'showCount': ps,
  14. 'totalPage': math.ceil(self.page.paginator.count * 1.0 / ps),
  15. 'totalResult': self.page.paginator.count,
  16. 'currentPage': self.page.number,
  17. 'count': self.page.paginator.count,
  18. 'data': data
  19. })