feat: prefill values

This commit is contained in:
moanos [he/him] 2024-05-30 09:57:20 +02:00
parent c9cd63b6a0
commit ba5c165ce0
2 changed files with 13 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import datetime import datetime
from django import forms from django import forms
from .models import AdoptionNotice, Animal, Image, Report, ModerationAction, User, Species from .models import AdoptionNotice, Animal, Image, Report, ModerationAction, User, Species
from django_registration.forms import RegistrationForm from django_registration.forms import RegistrationForm
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper

View File

@ -47,7 +47,18 @@ def adoption_notice_detail(request, adoption_notice_id):
return render(request, 'fellchensammlung/details/detail_adoption_notice.html', context=context) return render(request, 'fellchensammlung/details/detail_adoption_notice.html', context=context)
def adoption_notice_edit(request, adoption_notice_id): def adoption_notice_edit(request, adoption_notice_id):
form = AdoptionNoticeForm() """
Form to update adoption notices
"""
adoption_notice = AdoptionNotice.objects.get(pk=adoption_notice_id)
if request.method == 'POST':
form = AdoptionNoticeForm(request.POST)
if form.is_valid():
adoption_notice_instance = form.save()
return redirect(reverse("adoption-notice-detail", args=[adoption_notice_instance.pk], ))
else:
form = AdoptionNoticeForm(instance=adoption_notice)
return render(request, 'fellchensammlung/forms/form-adoption-notice.html', context={"form": form}) return render(request, 'fellchensammlung/forms/form-adoption-notice.html', context={"form": form})
def animal_detail(request, animal_id): def animal_detail(request, animal_id):