2017-04-24 13 views
0

変数を渡す方法done()SearchAdvertResultView(ListView)から変数を渡す方法(min_amountmax_amountListViewにパラメータを渡す方法は?

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)) 
... 
0123いくつかのオブジェクトの


完了()メソッド

答えて

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)) 
関連する問題