Created
November 15, 2019 07:43
-
-
Save Cguilliman/bfdbf3c8ad6dbeb89deb3fdbeaffd183 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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