django templates - Filtering results and pagination -
i have template shows filter form , below list of result records. bind form request filter form sets options user submitted when results returned.
i use pagination. using code in pagination documentation means when user clicks next page, form data lost.
what best way of dealing pagination , filtering in way?
- passing querystring paginiation links.
- change pagination links form buttons , therefore submit filter form @ same time, assumes user hasn't messed filter options.
- as above original data hidden fields.
alj
if don't mind tweaking urls bit can embed filter options directly url. has nice side benefit of making search options bookmarkable. when user clicks next/prev buttons on pagination information carried forward url.
you may have split urls page tad though. if you've used keyword args view function though, can put logic view in 1 function.
quick example
in urls.py
urlpatterns = patterns('', (r'^some_url/to/form/$', 'myapp.myview'), (r'^some_url/to/form/(?p<filter>[^/]+)/$', 'myapp.myview'), )
then in view.py
def myview(request, filter=none): if request.method == 'post': # if form valid redirect user url # filter args embedded elif filter none: form = myform() # init blank defaults elif filter not none: # convert filter args dict data = {'my_form_field' : filter} form = myform(data) else: # sanity checking in case missed case. raise exception. # rest of display logic initialized form
there cases using solution not apply, without knowing more specific case, can't say.
hope helps!
Comments
Post a Comment