Skip to content

Instantly share code, notes, and snippets.

@Cguilliman
Created November 15, 2019 07:43
Show Gist options
  • Save Cguilliman/bfdbf3c8ad6dbeb89deb3fdbeaffd183 to your computer and use it in GitHub Desktop.
Save Cguilliman/bfdbf3c8ad6dbeb89deb3fdbeaffd183 to your computer and use it in GitHub Desktop.
from collections import OrderedDict
from rest_framework.pagination import PageNumberPagination as BasePageNumberPagination
from rest_framework.response import Response
__all__ = (
'PageNumberPagination',
'paginator_generate',
)
class PageNumberPagination(BasePageNumberPagination):
def get_paginated_response(self, data):
return Response(OrderedDict([
('pagination', {
'limit': self.page.paginator.per_page,
'offset': (self.page.paginator.per_page * self.page.number) or 0,
'total': self.page.paginator.count,
# 'next': self.get_next_link(),
# 'previous': self.get_previous_link(),
}),
('data', data)
]))
def paginator_generate(page_size_, max_page_size_=None):
class Klass(PageNumberPagination):
page_size = page_size_
max_page_size = max_page_size_ or page_size_
return Klass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment