From a14ab339272a3f5388107a844b6efe0983190da4 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Mon, 27 May 2019 15:18:57 +0200 Subject: [PATCH] implement issues index and detail view, using templates --- issues/templates/issues/detail.html | 6 ++++++ issues/templates/issues/index.html | 11 +++++++++++ issues/urls.py | 4 +++- issues/views.py | 17 ++++++++++++++--- 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 issues/templates/issues/detail.html create mode 100644 issues/templates/issues/index.html diff --git a/issues/templates/issues/detail.html b/issues/templates/issues/detail.html new file mode 100644 index 0000000..42ea47c --- /dev/null +++ b/issues/templates/issues/detail.html @@ -0,0 +1,6 @@ +

#{{ issue.id }}: {{ issue.title }}

+

+ Project: {{ issue.project }}
+ Created: {{ issue.create_date }} +

+

{{ issue.text }}

\ No newline at end of file diff --git a/issues/templates/issues/index.html b/issues/templates/issues/index.html new file mode 100644 index 0000000..bcf3760 --- /dev/null +++ b/issues/templates/issues/index.html @@ -0,0 +1,11 @@ +{% if issue_list %} + +{% else %} +

No issues.

+{% endif %} \ No newline at end of file diff --git a/issues/urls.py b/issues/urls.py index 2fcca0d..93ae9ac 100644 --- a/issues/urls.py +++ b/issues/urls.py @@ -2,6 +2,8 @@ from django.urls import path from . import views +app_name = 'issues' urlpatterns = [ - path('', views.index, name='index') + path('', views.index, name='index'), + path('/', views.detail, name='detail'), ] diff --git a/issues/views.py b/issues/views.py index 3879a9b..b6d463a 100644 --- a/issues/views.py +++ b/issues/views.py @@ -1,6 +1,17 @@ -# from django.shortcuts import render -from django.http import HttpResponse +from django.shortcuts import get_object_or_404, render + +from .models import Issue def index(request): - return HttpResponse('Hello Tofu.') + issue_list = Issue.objects.order_by('create_date') + return render(request, 'issues/index.html', { + 'issue_list': issue_list, + }) + + +def detail(request, issue_id): + issue = get_object_or_404(Issue, pk=issue_id) + return render(request, 'issues/detail.html', { + 'issue': issue, + })