Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add LimitOffsetPagination.get_count to allow method override #5846

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 10 additions & 11 deletions rest_framework/pagination.py
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.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring spacing should be fixed

try:
return queryset.count()
except (AttributeError, TypeError):
return len(queryset)


class CursorPagination(BasePagination):
"""
Expand Down