form
This commit is contained in:
parent
cd696ef6e4
commit
d08d86f99b
3 changed files with 46 additions and 7 deletions
28
fbf/forms.py
Normal file
28
fbf/forms.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from datetime import date
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .models import FallenBird
|
||||
|
||||
|
||||
class DateInput(forms.DateInput):
|
||||
input_type = "date"
|
||||
|
||||
|
||||
class BirdForm(forms.ModelForm):
|
||||
class Meta:
|
||||
widgets = {"date_found": DateInput()}
|
||||
model = FallenBird
|
||||
fields = [
|
||||
"bird",
|
||||
"date_found",
|
||||
"place",
|
||||
"rescuer",
|
||||
]
|
||||
labels = {
|
||||
"bird": _("Vogel"),
|
||||
"date_found": _("Datum des Fundes"),
|
||||
"place": _("Fundort"),
|
||||
"rescuer": _("Finder"),
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-08 15:45
|
||||
# Generated by Django 4.2.2 on 2023-06-10 19:52
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
@ -43,7 +43,7 @@ class Migration(migrations.Migration):
|
|||
serialize=False,
|
||||
),
|
||||
),
|
||||
("date_found", models.DateTimeField()),
|
||||
("date_found", models.DateField()),
|
||||
("place", models.CharField(max_length=256)),
|
||||
("created", models.DateTimeField(auto_now_add=True)),
|
||||
("updated", models.DateTimeField(auto_now=True)),
|
||||
|
|
21
fbf/views.py
21
fbf/views.py
|
@ -1,5 +1,6 @@
|
|||
from django.shortcuts import render, HttpResponse
|
||||
from django.shortcuts import render, HttpResponse, redirect
|
||||
from .models import FallenBird
|
||||
from .forms import BirdForm
|
||||
|
||||
|
||||
def bird_create(request):
|
||||
|
@ -9,7 +10,7 @@ def bird_create(request):
|
|||
def bird_all(request):
|
||||
birds = FallenBird.objects.all()
|
||||
context = {"birds": birds}
|
||||
return render(request, "fbf/birds_all.html", context)
|
||||
return render(request, "fbf/bird_all.html", context)
|
||||
|
||||
|
||||
def bird_recover_all(request):
|
||||
|
@ -18,12 +19,22 @@ def bird_recover_all(request):
|
|||
|
||||
def bird_single(request, id):
|
||||
bird = FallenBird.objects.get(id=id)
|
||||
context = {"bird": bird}
|
||||
return render(request, "fbf/birds_single.html", context)
|
||||
form = BirdForm(request.POST or None, request.FILES or None, instance=bird)
|
||||
if request.method == "POST":
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect("bird_all")
|
||||
context = {"form": form, "bird": bird}
|
||||
return render(request, "fbf/bird_single.html", context)
|
||||
|
||||
|
||||
def bird_delete(request, id):
|
||||
return HttpResponse(f"Show delete with ID {id}")
|
||||
bird = FallenBird.objects.get(id=id)
|
||||
if request.method == "POST":
|
||||
bird.delete()
|
||||
return redirect("bird_all")
|
||||
context = {"bird": bird}
|
||||
return render(request, "fbf/bird_delete.html", context)
|
||||
|
||||
|
||||
def bird_recover(request, id):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue