pagination.py 768 B

1234567891011121314151617181920212223
  1. from django.conf import settings
  2. from rest_framework import pagination
  3. from rest_framework.response import Response
  4. class PageNumberPagination(pagination.PageNumberPagination):
  5. last_page_strings = ["last"]
  6. max_page_size = settings.API_MAX_PAGE_SIZE
  7. page_query_param = "page"
  8. page_size = settings.API_DEFAULT_PAGE_SIZE
  9. page_size_query_param = "limit"
  10. def get_paginated_response(self, data):
  11. return Response({
  12. "count": self.page.paginator.count,
  13. "page": self.page.number,
  14. "num_pages": self.page.paginator.num_pages,
  15. "limit": self.page.paginator.per_page,
  16. "next": self.get_next_link(),
  17. "previous": self.get_previous_link(),
  18. "results": data,
  19. })