feat: Make proper animal edit form

This commit is contained in:
2025-06-16 23:03:22 +02:00
parent e132b1c9f6
commit 35ef6676a2
3 changed files with 14 additions and 18 deletions

View File

@@ -84,19 +84,7 @@ class AdoptionNoticeFormWithDateWidget(AdoptionNoticeForm):
class AnimalForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
if 'in_adoption_notice_creation_flow' in kwargs:
adding = kwargs.pop('in_adoption_notice_creation_flow')
else:
adding = False
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-animal card'
if adding:
self.helper.add_input(Submit('save-and-add-another-animal', _('Speichern und weiteres Tier hinzufügen')))
self.helper.add_input(Submit('save-and-finish', _('Speichern und beenden')))
else:
self.helper.add_input(Submit('submit', _('Speichern'), css_class="btn"))
template_name = "fellchensammlung/forms/form_snippets.html"
class Meta:
model = Animal

View File

@@ -1,8 +1,15 @@
{% extends "fellchensammlung/base_generic.html" %}
{% extends "fellchensammlung/base_bulma.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load widget_tweaks %}
{% block content %}
<h1>{% translate "Vermittlungsanzeige" %}</h1>
{% crispy form %}
<h1>{{ form.name.data }}</h1>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<input class="button is-primary" type="submit" value="{% translate "Speichern" %}">
<a class="button is-danger">{% translate "Löschen" %}</a>
</form>
{% endblock %}

View File

@@ -515,7 +515,8 @@ def animal_edit(request, animal_id):
"""Log"""
Log.objects.create(user=request.user, action="add_photo_to_animal",
text=f"{request.user} hat Tier {animal.pk} zum Tier geändert")
return redirect(reverse("adoption-notice-detail", args=[animal.adoption_notice.pk], ))
print(reverse("adoption-notice-detail", args=[animal.adoption_notice.pk], ))
return redirect(reverse("adoption-notice-detail-bulma", args=[animal.adoption_notice.pk], ))
else:
form = AnimalForm(instance=animal)
return render(request, 'fellchensammlung/forms/form-adoption-notice.html', context={"form": form})