Recently I was working with drf pagination class,PageNumberPagination.I may or may not have encountered a weird bug . The official docs mention,to overide the page size of PageNumberPagination we have to create a Custom paginator which overides the page size configuration like shown below
class StandardResultsSetPagination(PageNumberPagination):
page_size = 100
page_size_query_param = 'page_size'
max_page_size = 1000
class BillingRecordsView(generics.ListAPIView):
queryset = Billing.objects.all()
serializer_class = BillingRecordsSerializer
pagination_class = LargeResultsSetPagination
But when I tried to do the same the custom paginator was using the default setting as 100 Here's my snippet I used
class StandardResultsSetPagination(PageNumberPagination):
page_size = 10
page_size_query_param = 'page_size'
max_page_size = 100
class TrendingClassesView(ListAPIView):
pagination_class = StandardResultsSetPagination
serializer_class = BaseClassTileSerializer
queryset = BaseClass.objects.all()
One moment the code the working fine but after playing around with the page size for some time the paginator just stopped working, I have to do something like below to make the page size working
class StandardResultsSetPagination(PageNumberPagination):
page_size = 10
page_size_query_param = 'page_size'
max_page_size = 100
def get_page_size(self, request):
return 10
This is my rest framework settings
REST_FRAMEWORK = {
'UPLOADED_FILES_USE_URL':
True,
'DEFAULT_PARSER_CLASSES': [
'rest_framework.parsers.JSONParser',
'rest_framework.parsers.MultiPartParser',
'rest_framework.parsers.FileUploadParser',
'rest_framework.parsers.FormParser',
],
"TIME_FORMAT":
"%I:%M %p",
"TIME_INPUT_FORMATS": ["%I:%M %p", "%H:%M"],
}
I guess I may be doing something wrong but I am not able to find the mistake.