fix the category list

This commit is contained in:
Andreas Zweili 2017-12-17 19:37:49 +01:00
parent 6894a1bfba
commit e63627ca4f
2 changed files with 7 additions and 8 deletions

View File

@ -5,13 +5,13 @@
<body> <body>
<div id="content" class="flex"> <div id="content" class="flex">
<h1>Music Shop</h1> <h1>Music Shop</h1>
{% if parent_category_list %} {% if category_list %}
<ul> <ul>
{% for parent_category in parent_category_list %} {% for category, sub_category in category_list.items %}
<li><a href="{% url 'category' parent_category.id %}">{{ parent_category.name }}</a></li> <li><a href="{% url 'category' category.id %}">{{ category.name }}</a></li>
{% for category in category_list %} {% for i in sub_category %}
<ul> <ul>
<li><a href="{% url 'category' category.id %}">{{ category.name }}</a></li> <li><a href="{% url 'category' i.id %}">{{ i.name }}</a></li>
</ul> </ul>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}

View File

@ -12,13 +12,12 @@ def index(request):
category_list = {} category_list = {}
for i in parent_category_list: for i in parent_category_list:
category = Category.objects.filter(parent_category=i.id) category_list.update(
category_list[i] = category {i: Category.objects.filter(parent_category=i.id)})
template = loader.get_template('webshop/index.html') template = loader.get_template('webshop/index.html')
context = { context = {
'category_list': category_list, 'category_list': category_list,
'parent_category_list': parent_category_list,
} }
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))