From a7e2a7bfcdf9d10dd3f5c1061245f34a8e5227b6 Mon Sep 17 00:00:00 2001 From: Charlie McBride Date: Fri, 23 Mar 2018 18:25:43 -0400 Subject: [PATCH] Add LimitOffsetPagination.get_count to allow method override (#5846) * Add LimitOffsetPagination.get_count to allow method override * Format method docstring --- rest_framework/pagination.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 4a74b6ed5..1c57f17d3 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -45,16 +45,6 @@ def _divide_with_ceil(a, b): return a // b -def _get_count(queryset): - """ - Determine an object count, supporting either querysets or regular lists. - """ - try: - return queryset.count() - except (AttributeError, TypeError): - return len(queryset) - - def _get_displayed_page_numbers(current, final): """ This utility function determines a list of page numbers to display. @@ -332,7 +322,7 @@ class LimitOffsetPagination(BasePagination): template = 'rest_framework/pagination/numbers.html' def paginate_queryset(self, queryset, request, view=None): - self.count = _get_count(queryset) + self.count = self.get_count(queryset) self.limit = self.get_limit(request) if self.limit is None: return None @@ -468,6 +458,15 @@ class LimitOffsetPagination(BasePagination): ) ] + def get_count(self, queryset): + """ + Determine an object count, supporting either querysets or regular lists. + """ + try: + return queryset.count() + except (AttributeError, TypeError): + return len(queryset) + class CursorPagination(BasePagination): """