Hello,
I cant understand why my 'brand’ queryset under ProductsListView doesnt do anything. When I click on it, it does nothing.
views.py
class ProductsListView(ListView):
model = Product
template_name = 'products_list.html'
context_object_name = 'products'
def get_queryset(self):
products = Product.objects.all()
category_id = self.request.GET.get('category', None)
search = self.request.GET.get('search', None)
brand = self.request.GET.get('brand', None)
if brand is not None:
products = products.filter(brand__iexact=brand)
if search is not None:
products = products.filter(name__icontains=search)
if category_id is not None:
products = products.filter(category__id=int(category_id))
return products
template
<ul class="list-group">
<li class="list-group-item mr-3 dropdown-toggle" type="button" data-toggle="dropdown" id="BrandDropDown" aria-haspopup="true" aria-expanded="false">
Brand
<div class="dropdown-menu" aria-labelledby="BrandDropDown">
{% for p in products %}
<a class="dropdown-item" href="{% url 'products' %}?brand={{p.brand}}">{{p.brand}}</a>
{% endfor %}
</div>
</li>
</ul>
urls.py
path('products_list', views.ProductsListView.as_view(), name='products'),