Casting a raw query set as a list for pagination

2013-03-26 Thread chambers24889


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 %}


{{ r.data}}
{{ r.loc}}


{% 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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Pagination with file upload (MultiValueDictKeyError)

2013-04-15 Thread chambers24889
I have a simple form that takes a user upload, queries a database, and 
displays results in a table.  I receive the following error whenever I try 
to go to the second, third, fourth, etc page:

MultiValueDictKeyError at /result/ 

"Key 'batch' not found in "

 Request Method: GET  Request URL: http://xxx/result/?page=4  Django 
Version: 1.5  Exception Type: MultiValueDictKeyError  Exception Value: 

"Key 'batch' not found in "

 Exception Location: 
C:\Python27\lib\site-packages\django\utils\datastructures.py 
in __getitem__, line 295  Python Executable: C:\Python27\python.exe  Python 
Version: 2.7.3  Python Path: 

['C:\\Users\\xx',
 'C:\\Python27\\lib\\site-packages\\django_pagination-1.0.7-py2.7.egg',
 'C:\\Windows\\system32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages']

 Server time: Tue, 16 Apr 2013 00:48:23 -0400
I've found two possible causes: I'm using a "request.POST" on the objects 
I'm paginating when it should be a "request.GET".  The issue here is I 
believe I need to have this as a POST because I'm getting data from an 
uploaded file.

The second cause I do not understand, but it's at this link: 
https://django-pagination.googlecode.com/svn/trunk/docs/usage.txt under "A 
Note About Uploads".  I assume this is directed at implementing a paginator 
object in views.py, but my only pagination code are the tags in my results 
page template.  

Does anyone have experience with this issue and/or have a solution?

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.