Reputation: 251
How to pass variables (min_amount and max_amount) from done()
to SearchAdvertResultView(ListView)
?
done() method of some object:
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))
...
Upvotes: 1
Views: 1665
Reputation: 3100
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))
Upvotes: 1