[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
|
|
@ -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
Add a link
Reference in a new issue