mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-17 02:45:08 +00:00
added and modifid pagination
This commit is contained in:
46
base/pagination.py
Normal file
46
base/pagination.py
Normal file
@ -0,0 +1,46 @@
|
||||
"""
|
||||
web_admin pagination file
|
||||
"""
|
||||
# third party imports
|
||||
from collections import OrderedDict
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
|
||||
from account.utils import custom_response
|
||||
from base.constants import NUMBER
|
||||
|
||||
|
||||
class CustomPageNumberPagination(PageNumberPagination):
|
||||
"""
|
||||
custom paginator class
|
||||
"""
|
||||
# Set the desired page size
|
||||
page_size = NUMBER['ten']
|
||||
page_size_query_param = 'page_size'
|
||||
# Set a maximum page size if needed
|
||||
max_page_size = NUMBER['hundred']
|
||||
|
||||
def get_paginated_response(self, data):
|
||||
"""
|
||||
:param data: queryset to be paginated
|
||||
:return: return a OrderedDict
|
||||
"""
|
||||
return custom_response(None, OrderedDict([
|
||||
('count', self.page.paginator.count),
|
||||
('data', data),
|
||||
('current_page', self.page.number),
|
||||
('total_pages', self.page.paginator.num_pages),
|
||||
|
||||
|
||||
]))
|
||||
|
||||
def get_paginated_dict_response(self, data):
|
||||
"""
|
||||
:param data: queryset to be paginated
|
||||
:return: return a simple dict obj
|
||||
"""
|
||||
return {
|
||||
'current': self.page.number,
|
||||
'data': data,
|
||||
'total': self.page.paginator.count,
|
||||
'total_pages': self.page.paginator.num_pages,
|
||||
}
|
Reference in New Issue
Block a user