mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Get support for iterables on OffLimPage
This commit is contained in:
parent
5117800fc5
commit
1709e78a3f
|
@ -157,9 +157,18 @@ class OffsetLimitPage(object):
|
||||||
A base class to allow offset and limit when listing a queryset.
|
A base class to allow offset and limit when listing a queryset.
|
||||||
"""
|
"""
|
||||||
def __init__(self, queryset, offset, limit):
|
def __init__(self, queryset, offset, limit):
|
||||||
self.count = queryset.count()
|
self.count = self._set_count(queryset)
|
||||||
self.object_list = queryset[offset:offset + limit]
|
self.object_list = queryset[offset:offset + limit]
|
||||||
|
|
||||||
|
def _set_count(self, queryset):
|
||||||
|
try:
|
||||||
|
return queryset.count()
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
# AttributeError if object_list has no count() method.
|
||||||
|
# TypeError if object_list.count() requires arguments
|
||||||
|
# (i.e. is of type list).
|
||||||
|
return len(queryset)
|
||||||
|
|
||||||
|
|
||||||
class OffsetLimitPaginationSerializer(BasePaginationSerializer):
|
class OffsetLimitPaginationSerializer(BasePaginationSerializer):
|
||||||
""" OffsetLimitPage serializer """
|
""" OffsetLimitPage serializer """
|
||||||
|
|
Loading…
Reference in New Issue
Block a user