如何将变量( min_amount 和 max_amount )从done()
传递到SearchAdvertResultView(ListView)
?
done()方法:
def done(self)
...
min_amount = 100
max_amount = 500
return redirect(reverse('board:search-result'))
urls.py :
...
url(r'^results$',
SearchAdvertResultView.as_view(),
name='search-result',
),
...
views.py :
...
class SearchAdvertResultView(ListView):
template_name = "board/search_results.html"
def get_queryset(self):
...
return Adverts.objects.filter(amount__range=(min_amount, max_amount))
...
答案 0 :(得分:0)
def done(self)
...
min_amount = 100
max_amount = 500
urlparams = '?min_amount=%s&max_amount=%s' % (min_amount, max_amount)
return redirect(reverse('board:search-result')+urlparams)
class SearchAdvertResultView(ListView):
template_name = "board/search_results.html"
def get_queryset(self):
...
min_amount = self.request.GET.get('min_amount')
max_amount = self.request.GET.get('max_amount')
return Adverts.objects.filter(amount__range=(min_amount, max_amount))