pagination.py 874 B

12345678910111213141516171819202122232425262728
  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. print(self.page_size_query_param)
  11. ps = self.get_page_size(self.request)
  12. print(2222222222, self.page.paginator.count)
  13. print(3333333, self.page.number)
  14. print(444444, ps)
  15. print(555555, len(data))
  16. return Response({
  17. 'code':0,
  18. 'showCount': ps,
  19. 'totalPage': math.ceil(self.page.paginator.count * 1.0 / ps),
  20. 'totalResult': self.page.paginator.count,
  21. 'currentPage': self.page.number,
  22. 'count': self.page.paginator.count,
  23. 'data': data
  24. })