我尝试创建在线商店,因此无法同时过滤往返的品牌和价格。
我有一张表格。在模板中有字段(Brands,min_cena和max_cena)的地方,我在左侧有两列,例如在商店的所有站点中的一列中,在另一列中的品牌中,您可以在两个字段中设置价格的往返。相应地,我有两种形式的het方法和两个用于传递参数的按钮。如果在一个按钮下添加品牌和价格字段的输出以提交,则一切正常。但这看起来很难看,我单独将其提供给请求或价格或品牌。
class BrandForms(forms.Form):
brand = forms.ModelMultipleChoiceField(queryset=Vendor.objects.none(), widget=forms.CheckboxSelectMultiple(), required=False)
min_price = forms.IntegerField(label='от', required=False)
max_price = forms.IntegerField(label='до', required=False)
filter_brand = BrandForms(request.GET)
if filter_brand.is_valid():
if filter_brand.cleaned_data['brand']:
print(filter_brand.cleaned_data['brand'])
list_pro = Product.objects.filter(category__in=Category.objects.get(id=category.id)\
.get_descendants(include_self=True)) \
.annotate(min_price=Min('prices__price'))\
.filter(vendor__in=filter_brand.cleaned_data['brand'])
products_list = helpers.pg_records(request, list_pro, 12)
if filter_brand.is_valid():
if filter_brand.cleaned_data['min_price']:
list_pro = list_pro.filter(prices__price__gte=filter_brand.cleaned_data['min_price'])
products_list = helpers.pg_records(request, list_pro, 12)
{% if vendors.count >= 10 and vendors%}
<div class="shop-sidebar mb-35">
<h4 class="title" data-spy="scroll" data-target="#brand_liste">Бренды</h4>
<form id="form1" action="." method="get">
<div class="input-group">
<input id="brand_list_input" type="text" class="form-control" placeholder="Поиск бренда" aria-label="Recipient's username" aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="px-3" type="submit"><i class="fas fa-search"></i></button>
</div>
</div>
<ul class="sidebar-brand position-relative" id="brand_liste" style="height: 450px; overflow-y: scroll;">
{{ filter_brand }}
</ul>
</form>
</div>
{% elif vendors %}
<div class="shop-sidebar mb-35">
<h4 class="title" data-spy="scroll" data-target="#brand_liste">Бренды</h4>
<form id="1" action="." method="get">
<div class="input-group">
<input id="brand_list_input" type="text" class="form-control" placeholder="Поиск бренда" aria-label="Recipient's username" aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="px-3" type="submit"><i class="fas fa-search"></i></button>
</div>
</div>
<ul class="sidebar-brand position-relative" id="brand_liste">
{{ filter_brand }}
</ul>
</form>
</div>
{% endif %}
<!-- END BRANDS -->
<div class="shop-sidebar mb-35">
<h4 class="title">Price</h4>
<form method="get" action=".">
{{ filter_brand.brand.disabled}}
{{ filter_brand.min_price }}
<button type="submit">Поиск</button>
</form>
<div class="sidebar-price">
</div>
</div>