15👍
You can define _count variable in your paginator
paginator = Paginator(QuerySet, 300)
paginator._count = 9000 # or use some query here
And here is the part of django paginator code to help you understand what this variable do and how page count works
def _get_count(self):
"Returns the total number of objects, across all pages."
if self._count is None:
try:
self._count = self.object_list.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).
self._count = len(self.object_list)
return self._count
count = property(_get_count)
👤errx
2👍
You can pass the count by yourself
paginator = Paginator(models ,25 )
paginator.count=100000
or if you want the exact count you can use
count=int(model.objects.latest('id').id)
paginator = Paginator(models ,25 )
paginator.count=count
- How to get average from set of objects in Django?
- Django admin enable sorting for calculated fields
- Django version of flask.jsonify jsonify
-1👍
You could also check out django-endless-pagination.endless_pagination.paginator.LazyPaginator
is not bad, but you might need to add a few tweaks.
- TypeError: ‘DoesNotExist’ object is not callable
- Getting error with is_popup variable in django 1.9
- 'Questions ' object is not iterable Django
- Running collectstatic on server : AttributeError: 'PosixPath' object has no attribute 'startswith'
- Django-Rest-Framework serializer class meta
Source:stackexchange.com