Django-pagination breaks my order_by -
in html-template load list of objects , i'm trying combine django-pagination (from docs) , order_by method.
i tried put ordering-links loads href="/mylist/?order_by=somefield
it works on first page. order seems break when i'm clicking "next page". what's problem here?
"next page" link loads href="mylist/?page={{ results.next_page_number }}
view:
def mylist(request): order_by = request.get.get('order_by', 'somedefault') myobjects_list = mymodel.objects.filter(user=request.user).order_by(order_by) paginator = paginator(myobjects_list, 5) page = request.get.get('page') try: results = paginator.page(page) except pagenotaninteger: results = paginator.page(1) except emptypage: results = paginator.page(paginator.num_pages) context = {'results ': results } return render_to_response('mylist.html', context, context_instance=requestcontext(request))
in view:
context = {'results ': results, 'order_by': order_by}
in template:
href="mylist/?page={{ results.next_page_number }}&order_by={{ order_by }}"
Comments
Post a Comment