From 4f18318b1cab0baf15ea8a8ce5556b928e15f391 Mon Sep 17 00:00:00 2001 From: Christophe Henry Date: Fri, 26 May 2023 12:43:59 +0200 Subject: [PATCH] Allow REST_FRAMEWORK.PAGE_SIZE to be overriden in settings --- rest_framework/pagination.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index af508bef6d..ff5182a483 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -166,9 +166,6 @@ class PageNumberPagination(BasePagination): http://api.example.org/accounts/?page=4 http://api.example.org/accounts/?page=4&page_size=100 """ - # The default page size. - # Defaults to `None`, meaning pagination is disabled. - page_size = api_settings.PAGE_SIZE django_paginator_class = DjangoPaginator @@ -191,6 +188,13 @@ class PageNumberPagination(BasePagination): invalid_page_message = _('Invalid page.') + @property + def page_size(self): + # The default page size. + # Defaults to `None`, meaning pagination is disabled. + # Property so that PAGE_SIZE can be overriden by @override_settings + return api_settings.PAGE_SIZE + def paginate_queryset(self, queryset, request, view=None): """ Paginate a queryset if required, either returning a