M
M
maxell2019-11-09 01:45:07
Django
maxell, 2019-11-09 01:45:07

How to get 2 get parameters?

There are 2 forms. 1 - search, 2 filter
1.

<form class="form" action =" {% url 'search' %}" >
                    <div class="input-group">
                        <input class="form-control border-right-0 border " type="search" placeholder="Искать товары", name="search">
                        <span class="input-group-append">
                            <div class="input-group-text bg-transparent p-0">
                            </div>
                            <button class="btn btn-outline-success " type="submit"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </form>

2.
<form class="form for_change_items" method="get" name ="a" > 
                                                                 
                                        <div class="form-check p-0  " >


                                            <input class="form-check-input"  type="radio" onClick="a.submit()"  name="model_or_item"  id="model" value="model">
                                            <input class="form-check-input"  type="radio" onClick="a.submit()"  name="model_or_item" id="item" value="item" >

                                            <a class= "gray_text">{{items.count }} товар (-а, -ов)</a>

                                            <input class="form-check-input" type="radio" name="change_items" onClick="a.submit()" checked id="2_items" value="2_items" >
                                            <input class="form-check-input" type="radio" name="change_items" onClick="a.submit()"  id="many_items" value="many_items">
                                            <label  {% if model_or_item == 'item' %} style="  opacity:0.7;" {% endif %} class="form-check-label font-weight-bolder" for="model">
                                                <a  {% if model_or_item == 'model' %} style=" text-decoration: underline;" {% endif %}>Модель</a>
                                            </label>
                                            <label  {% if model_or_item == 'model' %} style=" opacity:0.7;" {% endif %} class="form-check-label font-weight-bolder " for="item">
                                                <a  {% if model_or_item == 'item' %} style=" text-decoration: underline;" {% endif %}>Изделие</a>
                                            </label> 
                                            
                                        </div>
                                        
                                    </form>

how do i get them in views.py
search = request.GET.get('search')
change_items = request.GET.get('change_items', '2_items')
model_or_item = request.GET.get('model_or_item', 'model')
items = Item.objects.filter(title__icontains = search)

If I search for something and then start filtering the product, the page reloads and search becomes None.
How to store value in search variable

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question