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?
django pagination and RawQuerySet
6.4k Views Asked by mossplix At
3
There are 3 best solutions below
1

qs.filter(**pfilter).distinct().extra(select={'test': 'COALESCE(`psearch_program`.`eu_price`, 999999999)'}).extra(order_by=['test'])
3

You can set the attribute count manually for your RawQuerySet object:
items = Item.objects.raw("select * from appitem_item")
def items_count():
cursor = connection.cursor()
cursor.execute("select count(*) from appitem_item")
row = cursor.fetchone()
return row[0]
items.count = items_count
for @Rockallite
>>> class A():
... def b(self):
... print 'from b'
...
>>>
>>> (A()).b()
from b
>>> def c():
... print 'from c'
...
>>> a = A()
>>> a.b = c
>>> a.b()
from c
I managed to achieve it using the following:
The code in django.core.paginator.py:
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