[collector view] rudimentary implementation of list and detail view
This commit is contained in:
parent
d6ff246804
commit
6214610edc
4 changed files with 36 additions and 3 deletions
2
collector/templates/collector/detail.html
Normal file
2
collector/templates/collector/detail.html
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>{{ teil.name }}</h1>
|
||||||
|
Last Changed: {{ teil.modified }}
|
||||||
17
collector/templates/collector/index.html
Normal file
17
collector/templates/collector/index.html
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
{% if teile_list %}
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{% for teil in teile_list %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'collector:detail' teil.id %}">
|
||||||
|
{{ teil.name }}
|
||||||
|
</a> ({{ teil.modified }})
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
<p>Keine Teile da.</p>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
@ -2,6 +2,9 @@ from django.urls import path
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
|
app_name = "collector"
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", views.index, name="index"),
|
path("", views.index, name="index"),
|
||||||
|
path("recorded/<int:teil_id>/", views.detail, name="detail"),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,17 @@
|
||||||
|
from django.http import HttpRequest, HttpResponse
|
||||||
|
from django.shortcuts import get_object_or_404, render
|
||||||
|
|
||||||
from django.http import HttpResponse
|
from .models import Teil
|
||||||
|
|
||||||
|
|
||||||
def index(request) -> HttpResponse:
|
def index(request: HttpRequest) -> HttpResponse:
|
||||||
return HttpResponse("hello tutorial")
|
teile_list = Teil.objects.order_by("-modified")[:10]
|
||||||
|
context = {
|
||||||
|
"teile_list": teile_list,
|
||||||
|
}
|
||||||
|
return render(request, "collector/index.html", context)
|
||||||
|
|
||||||
|
|
||||||
|
def detail(request: HttpRequest, teil_id) -> HttpResponse:
|
||||||
|
teil = get_object_or_404(Teil, pk=teil_id)
|
||||||
|
return render(request, "collector/detail.html", {"teil": teil})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue