我有一个网站,基本上显示了一个巨大的人员表,我希望能够过滤,排序和翻页。我想在多个视图中执行此操作,这些视图具有不同的预先存在的约束,人们在表中显示。我的问题是,如果我按状态过滤,按名称排序,然后尝试转到下一页,它会重置。例如,如果我过滤了我的/ url / 2013 /?sort = n& state = MN& page = 1;然后,如果我转到第2页,我只是得到我的/ url / 2013 /?page = 2。它不记得我已经问过它了。
def all(request, year=default_year):
#sorting (sort_options was defined prior to this view)
if 'sort' in request.GET:
sort = request.GET.get('sort')
order = sort_options[sort]
else:
order = '-score'
players = Player.objects.filter(year=year).order_by(order)
url_query = ''
#filtering
if 'position' in request.GET:
filterData = _filter(request,players)
players = filterData['players']
url_query += filterData['url_query']
# pagination
paginator = Paginator(players,25)
page = request.GET.get('page')
try:
players = paginator.page(page)
except PageNotAnInteger:
players = paginator.page(1)
except EmptyPage:
players = paginator.page(paginator.num_pages)
data = {'players':players,'url_query':url_query}
return render_to_response('all.html', data, context_instance = RequestContext(request))
在我的模板中,我像这样引用url_query:
<th class="name"><a href="?sort=n&{{url_query}}&page={{players.number}}">Name</a></th>
并且像这样:
<a href="?{{url_query}}&page={{ players.next_page_number }}">Next</a>
这对我来说显然是错误的,但我不知道该怎么做。