[collector] can now collect Teile and list them
If a newly entered Teil already exists, we ignore that and do nothing. "name" could become a primary key...
This commit is contained in:
parent
1870d50ccf
commit
27c9a3a35b
4 changed files with 39 additions and 1 deletions
collector
|
@ -1,2 +1,17 @@
|
|||
<h1>{{ teil.name }}</h1>
|
||||
Last Changed: {{ teil.modified }}
|
||||
|
||||
<hr>
|
||||
|
||||
<form action="{% url 'collector:detail' teil.id %}" method="POST">
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
<legend>
|
||||
<h1>{{ teil.name }}</h1>
|
||||
</legend>
|
||||
{% if error_message %}
|
||||
<p><strong>{{ error_message }}</strong></p>
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
<input type="submit" name="submit" value="enter it!">
|
||||
</form>
|
||||
|
|
|
@ -15,3 +15,9 @@
|
|||
<p>Keine Teile da.</p>
|
||||
|
||||
{% endif %}
|
||||
|
||||
<form method="POST" action="{% url 'collector:enter' %}">
|
||||
{% csrf_token %}
|
||||
<input type="text" name="new_name" value="">
|
||||
<input type="submit" name="submit" value="add new Teil">
|
||||
</form>
|
||||
|
|
|
@ -7,4 +7,6 @@ app_name = "collector"
|
|||
urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
path("recorded/<int:teil_id>/", views.detail, name="detail"),
|
||||
path("enter/", views.enter, name="enter"),
|
||||
path("all/", views.list_all, name="all"),
|
||||
]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.urls import reverse
|
||||
|
||||
from .models import Teil
|
||||
|
||||
|
@ -12,6 +13,20 @@ def index(request: HttpRequest) -> HttpResponse:
|
|||
return render(request, "collector/index.html", context)
|
||||
|
||||
|
||||
def list_all(request: HttpRequest) -> HttpResponse:
|
||||
teile_list = Teil.objects.order_by("-modified")
|
||||
return render(request, "collector/index.html", {"teile_list": teile_list})
|
||||
|
||||
|
||||
def detail(request: HttpRequest, teil_id) -> HttpResponse:
|
||||
teil = get_object_or_404(Teil, pk=teil_id)
|
||||
return render(request, "collector/detail.html", {"teil": teil})
|
||||
|
||||
|
||||
def enter(request: HttpRequest) -> HttpResponse:
|
||||
try:
|
||||
Teil.objects.create(name=request.POST["new_name"])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return HttpResponseRedirect(reverse("collector:index"))
|
||||
|
|
Loading…
Add table
Reference in a new issue