implement issues index and detail view, using templates
This commit is contained in:
parent
43c127d744
commit
a14ab33927
|
|
@ -0,0 +1,6 @@
|
||||||
|
<h2>#{{ issue.id }}: {{ issue.title }}</h2>
|
||||||
|
<p>
|
||||||
|
<b>Project:</b> {{ issue.project }}<br/>
|
||||||
|
<b>Created:</b> {{ issue.create_date }}
|
||||||
|
</p>
|
||||||
|
<p>{{ issue.text }}</p>
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
{% if issue_list %}
|
||||||
|
<ul>
|
||||||
|
{% for issue in issue_list %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'issues:detail' issue.id %}">{{ issue.title }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>No issues.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
@ -2,6 +2,8 @@ from django.urls import path
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
|
app_name = 'issues'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index')
|
path('', views.index, name='index'),
|
||||||
|
path('<int:issue_id>/', views.detail, name='detail'),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,17 @@
|
||||||
# from django.shortcuts import render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.http import HttpResponse
|
|
||||||
|
from .models import Issue
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
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,
|
||||||
|
})
|
||||||
|
|
|
||||||
Reference in New Issue