Saturday, April 26, 2014

Re: Casting a raw query set as a list for pagination

I've created a paginator for RawQuerySets.  https://github.com/seamusmb/django-paginator-rawqueryset

On Tuesday, March 26, 2013 5:51:41 AM UTC-4, chambe...@gmail.com wrote:

I'm trying to implement Django's built in pagination feature with a raw query set. I've researched the issue and the answer is I need to cast my set as a list. Something like this:

paginator = Paginator(refg, 100) # Show 100 contacts per page  paginator._count = len(list(refg))

From my understanding, setting the count field for the paginator should prevent Django from trying to get the size of my raw set, but this is not the case. I'm still getting the "RawQuerySet has no len() operation" error. I've attched the relevant code from my views.py and my template.

Can I get some advice as to how I can fix this error?


views.py

refg = RefGene.objects.raw(qrefg)

paginator = Paginator(refg, 100) # Show 100 contacts per page
paginator._count = len(list(refg))

# using django's generated forms
c = RequestContext(request, {
    "refg": refg, ... })

return HttpResponse(t.render(c))

template

{% autopaginate refg %} {% for r in refg %} <tr> <td>{{ r.data}}</td> <td>{{ r.loc}}</td> </tr> {% endfor %} {% paginate %}

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/86cd1c6d-5e2d-409c-8ce7-f911c61fe856%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment