pagination.py 880 B

1234567891011121314151617181920212223242526272829
  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. # 底栏合计
  12. totalRow = {}
  13. if len(data) > 0 and 'totalRow' in data[-1:][0]:
  14. totalRow = data[-1:][0]
  15. data = data[:-1]
  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. 'totalRow': totalRow,
  24. 'data': data
  25. })