diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index b31d1f6b6..c3c06ac34 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -157,9 +157,18 @@ class OffsetLimitPage(object): A base class to allow offset and limit when listing a queryset. """ def __init__(self, queryset, offset, limit): - self.count = queryset.count() + self.count = self._set_count(queryset) 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): """ OffsetLimitPage serializer """