Skip to content

Add LimitOffsetPagination.get_count to allow method override #5846

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Mar 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions rest_framework/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -468,6 +458,15 @@ def get_schema_fields(self, view):
)
]

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):
"""
Expand Down