2025-06-07 09:18:27 +03:30
|
|
|
from rest_framework.pagination import PageNumberPagination
|
2025-09-03 14:23:04 +03:30
|
|
|
from rest_framework.response import Response
|
2025-06-07 09:18:27 +03:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomPageNumberPagination(PageNumberPagination):
|
|
|
|
|
page_size = 20 # default
|
|
|
|
|
page_size_query_param = 'page_size' # set from client
|
|
|
|
|
max_page_size = 100 # maximum items to show
|
2025-09-03 14:23:04 +03:30
|
|
|
message = None
|
|
|
|
|
|
|
|
|
|
def get_paginated_response(self, data):
|
|
|
|
|
return Response({
|
|
|
|
|
'message': self.message, # Custom message
|
|
|
|
|
'count': self.page.paginator.count,
|
|
|
|
|
'next': self.get_next_link(),
|
|
|
|
|
'previous': self.get_previous_link(),
|
|
|
|
|
'results': data
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
def set_message(self, message):
|
|
|
|
|
self.message = message
|