1

I'm having trouble using djangoś paginator function. In this question i can't find the solution: Django: Paginator + raw SQL query

With Table.object.all() i have no trouble, but with raw sql i receive the error object of type 'RawQuerySet' has no len()

I tried also

num = len(list(ads)) paginator = Paginator(num, 2)

and i receive object of type 'int' has no len(). I tried to print num and it contains the correct number so i don't understand why paginator doesn't like it. Hope someone can help.

Community
  • 1
  • 1
Mark
  • 645
  • 2
  • 9
  • 27

1 Answers1

1

Found the solution here: http://groups.google.com/group/django-users/browse_thread/thread/42cf7b5a88f31b9c

that means:

paginator = Paginator((list(ads)), 10)
Mark
  • 645
  • 2
  • 9
  • 27
  • 3
    This could be very ineffective. On normal QuerySets, paginator can use COUNT, LIMIT and OFFSET to get the required subset of results. But in case of RawQuerySet, your solution will fetch ALL the possible results and then slice the list in python. – Beli Feb 06 '14 at 11:38