{% for top in topwear.brand %} не выполняется
Я хочу перечислить товары по брендам, чтобы пользователь мог выбирать в соответствии с брендом товара в боковой панели, но почему-то этого не происходит
views.py
class home(View):
def get (self,request):
products=Product.objects.all()
topwear=Product.objects.filter(Category='TW')
bottomwear=Product.objects.filter(Category='BW')
context={'topwear':topwear,'bottomwear':bottomwear,'products':products}
return render(request,'store/index.html',context)
models.py
class Product(models.Model):
category=[
('TW','Top Wear'),
('BW','Bottom Wear'),
('Shoes','Shoes'),
('mobile','mobile'),
('Laptop','Laptop')
]
title=models.CharField(max_length=100)
selling_price=models.FloatField()
discounted_price=models.FloatField()
description=models.TextField()
brand=models.CharField(max_length=100)
Category=models.CharField(choices=category,max_length=10)
product_image=models.ImageField(upload_to='productimg')
def __str__(self):
return str(self.id)
Раздел нижней одежды и мобильных устройств отображается, а раздел верхней одежды - нет.
index.html
your text
<div class="dropdown-menu position-absolute bg-secondary border-0 rounded-0 w-100 m-0">
{% for top in topwear.brand %}
<a href="{% url 'searchproduct' top %}" class="dropdown-item">Top Wear</a>
{% endfor %}
<a href="" class="dropdown-item">Bottom Wear</a>
<a href="" class="dropdown-item">Mobile</a>
</div>
Все остальное работает .Только верхняя секция одежды не отображается в браузере. Является ли этот синтаксис неправильным?
Помощь будет оценена по достоинству
Вместо этого:
{% for top in topwear.brand %}
<a href="{% url 'searchproduct' top %}" class="dropdown-item">Top Wear</a>
{% endfor %}
попробуйте это:
{% for top in topwear %}
<a href="{% url 'searchproduct' top.brand %}" class="dropdown-item">Top Wear</a>
{% endfor %}
{% for top in topwear %}
<a href="{% url 'searchproduct' top.brand %}" class="dropdown-item">Top Wear</a>
{% endfor %}