python - Change number of items per page or view all in a view using a paginator in django -


i using django 1.3 , have view takes paginated queryset (set use 50 objects). here relevant part of get_context_data() method in view:

    #build paginator querysets     paginated_scanned_assets = paginator(scanned_assets_qs, 50)      #get specified page     try:         page_num = int(self.request.get.get('page', '1'))     except valueerror:         page_num = 1      #get paginated list of object     try:         scanned_assets = paginated_scanned_assets.page(page_num)     except (emptypage, invalidpage):         scanned_assets = paginated_scanned_assets.page(paginated_scanned_assets.num_pages) 

the template renders builds table queryset , has links go next , previous pages.

what want either have link view all, display queryset unpaginated, or option modify number of objects per page (which recreate paginator). haven't worked views or design though not sure how this. can js, , if how? otherwise can django , html? might simple, pretty inexperienced , haven't found answer or example anywhere.

thanks!

what want add optional parameter view called 'page_size' , like:

def your_view(request, ..., page_size=50):   scanned_assets_qs = # scanned_assets queryset    if page_size == -1:     page_size = scanned_assets_qs.count()    paginator = paginator(scanned_assets_qs, page_size) 

then can pass in arbitrary page_size, , -1 view page (i appropriate urls, plus url /viewall/ passes in -1 no matter what)


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -