mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
Add LimitOffsetPagination.get_count to allow method override (#5846)
* Add LimitOffsetPagination.get_count to allow method override * Format method docstring
This commit is contained in:
parent
5e6abfbafe
commit
a7e2a7bfcd
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user