[Django]-How to prevent a row count from being sent to the db when paginator is disabled

3👍

This was a bug in django-tables2 and should be fixed with commit 942f05e.

The fix is released as version 1.21.1.

👤Jieter

-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
👤SuReSh

Leave a comment