add a view to list all articles in a category
This commit is contained in:
parent
a73f48a40a
commit
7c5af973f2
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="{{ STATIC_URL }}/static/admin/css/base.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="content" class="flex">
|
||||
<h1>{{ category.name }}</h1>
|
||||
{% if article_list %}
|
||||
<ul>
|
||||
{% for article in article_list %}
|
||||
<li><a href="{% url 'details' article.id %}">{{ article.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>There are no articles in this category.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -4,4 +4,7 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.index, name='index'),
|
||||
url(r'^category/(?P<category_id>[0-9]+)/$',
|
||||
views.articles_in_category,
|
||||
name='category'),
|
||||
]
|
||||
|
|
|
@ -21,3 +21,18 @@ def index(request):
|
|||
'parent_category_list': parent_category_list,
|
||||
}
|
||||
return HttpResponse(template.render(context, request))
|
||||
|
||||
|
||||
def articles_in_category(request, category_id):
|
||||
selected_category = Category.objects.get(id=category_id)
|
||||
hidden = ArticleStatus.objects.get(name="hidden")
|
||||
|
||||
article_list = Article.objects.filter(
|
||||
category=selected_category.id).exclude(status=hidden.id)
|
||||
|
||||
template = loader.get_template('webshop/category.html')
|
||||
context = {
|
||||
'article_list': article_list,
|
||||
'category': selected_category,
|
||||
}
|
||||
return HttpResponse(template.render(context, request))
|
||||
|
|
Loading…
Reference in New Issue