From 6894a1bfbad14b5658c0bbcd8cf122b07e2dd00d Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sun, 17 Dec 2017 10:37:04 +0100 Subject: [PATCH] add a view to show the details of an article --- .../templates/webshop/article_details.html | 15 +++++++++++++++ django/didgeridoo/webshop/urls.py | 3 +++ django/didgeridoo/webshop/views.py | 7 +++++++ 3 files changed, 25 insertions(+) create mode 100644 django/didgeridoo/webshop/templates/webshop/article_details.html diff --git a/django/didgeridoo/webshop/templates/webshop/article_details.html b/django/didgeridoo/webshop/templates/webshop/article_details.html new file mode 100644 index 0000000..aa66890 --- /dev/null +++ b/django/didgeridoo/webshop/templates/webshop/article_details.html @@ -0,0 +1,15 @@ + + + + + +
+

{{ article.name }}

+

Description

+

{{ article.description }}

+

Stock: {{ article.stock }}

+

Status: {{ article.status}}

+

Price: {{ article.price_in_chf }}

+
+ + diff --git a/django/didgeridoo/webshop/urls.py b/django/didgeridoo/webshop/urls.py index 1e36cbc..ae62468 100644 --- a/django/didgeridoo/webshop/urls.py +++ b/django/didgeridoo/webshop/urls.py @@ -4,6 +4,9 @@ from . import views urlpatterns = [ url(r'^$', views.index, name='index'), + url(r'^details/(?P[0-9]+)/$', + views.article_details, + name='details'), url(r'^category/(?P[0-9]+)/$', views.articles_in_category, name='category'), diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index e39b894..7cf7d2a 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -36,3 +36,10 @@ def articles_in_category(request, category_id): 'category': selected_category, } return HttpResponse(template.render(context, request)) + + +def article_details(request, article_id): + article = get_object_or_404(Article, pk=article_id) + return render(request, + 'webshop/article_details.html', + {'article': article})