3👍
✅
This was a bug in django-tables2 and should be fixed with commit 942f05e.
The fix is released as version 1.21.1.
-1👍
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
class PaginateQueryset(object):
'''Paginate Queryset'''
def paginate_query_set(self, queryset, page_size):
''' Paginate '''
page = self.search_params.get('page', 1)
paginator = Paginator(queryset, page_size)
try:
objects = paginator.page(page)
except PageNotAnInteger:
objects = paginator.page(1)
except EmptyPage:
objects = paginator.page(paginator.num_pages)
return objects, paginator.count
def my_view(request):
queryset = my_model.objects.all()
result, count = PaginateQueryset.paginate_query_set(
queryset, 25)
return result, count
- [Django]-Alternative Django package for "django.core.xheaders" in Django 2.0
- [Django]-Get form data inside form class.
Source:stackexchange.com