Skip to content

Commit a7e2a7b

Browse files
chukkwagontomchristie
authored andcommitted
Add LimitOffsetPagination.get_count to allow method override (#5846)
* Add LimitOffsetPagination.get_count to allow method override * Format method docstring
1 parent 5e6abfb commit a7e2a7b

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

rest_framework/pagination.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ def _divide_with_ceil(a, b):
4545
return a // b
4646

4747

48-
def _get_count(queryset):
49-
"""
50-
Determine an object count, supporting either querysets or regular lists.
51-
"""
52-
try:
53-
return queryset.count()
54-
except (AttributeError, TypeError):
55-
return len(queryset)
56-
57-
5848
def _get_displayed_page_numbers(current, final):
5949
"""
6050
This utility function determines a list of page numbers to display.
@@ -332,7 +322,7 @@ class LimitOffsetPagination(BasePagination):
332322
template = 'rest_framework/pagination/numbers.html'
333323

334324
def paginate_queryset(self, queryset, request, view=None):
335-
self.count = _get_count(queryset)
325+
self.count = self.get_count(queryset)
336326
self.limit = self.get_limit(request)
337327
if self.limit is None:
338328
return None
@@ -468,6 +458,15 @@ def get_schema_fields(self, view):
468458
)
469459
]
470460

461+
def get_count(self, queryset):
462+
"""
463+
Determine an object count, supporting either querysets or regular lists.
464+
"""
465+
try:
466+
return queryset.count()
467+
except (AttributeError, TypeError):
468+
return len(queryset)
469+
471470

472471
class CursorPagination(BasePagination):
473472
"""

0 commit comments

Comments
 (0)