Search code examples
pythondjangodjango-pagination

django pagination and RawQuerySet


is there a way to paginate a rawqueryset using django's inbuilt pagination? when i cast it to a list , it throws an error in my face ...TypeError: expected string or Unicode object, NoneType found. Is there a way around this?


Solution

  • I managed to achieve it using the following:

    paginator = Paginator(files, 12)
    paginator._count = len(list(files))
    

    The code in django.core.paginator.py:

    • checks for whether _count is set
    • if not then tries to run .count() which doesn't exist
    • if not then tries plain len

    len on a raw_queryset doesn't work but converting the actual paginator object to a list works find for me in Django 1.3