add an index view and a coresponding template
This commit is contained in:
parent
83bb342383
commit
cc313a50f3
|
@ -0,0 +1,24 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="{{ STATIC_URL }}/static/admin/css/base.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="content" class="flex">
|
||||||
|
<h1>Music Shop</h1>
|
||||||
|
{% if parent_category_list %}
|
||||||
|
<ul>
|
||||||
|
{% for parent_category in parent_category_list %}
|
||||||
|
<li><a href="{% url 'category' parent_category.id %}">{{ parent_category.name }}</a></li>
|
||||||
|
{% for category in category_list %}
|
||||||
|
<ul>
|
||||||
|
<li><a href="{% url 'category' category.id %}">{{ category.name }}</a></li>
|
||||||
|
</ul>
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>No categories are available.</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,8 +1,23 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
from django.template import loader
|
||||||
|
|
||||||
|
from .models import Article, Category, ArticleStatus
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return HttpResponse("Hello, world. You're at the polls index.")
|
parent_category_list = Category.objects.filter(parent_category=None)
|
||||||
|
category_list = {}
|
||||||
|
|
||||||
|
for i in parent_category_list:
|
||||||
|
category = Category.objects.filter(parent_category=i.id)
|
||||||
|
category_list[i] = category
|
||||||
|
|
||||||
|
template = loader.get_template('webshop/index.html')
|
||||||
|
context = {
|
||||||
|
'category_list': category_list,
|
||||||
|
'parent_category_list': parent_category_list,
|
||||||
|
}
|
||||||
|
return HttpResponse(template.render(context, request))
|
||||||
|
|
Loading…
Reference in New Issue