From 3200ff7563fa451a19930e40a9f851aa48dc0010 Mon Sep 17 00:00:00 2001 From: SysAdmin Agent Date: Sat, 21 Mar 2026 22:02:07 +0000 Subject: [PATCH] =?UTF-8?q?Add=20Anrede=20field=20to=20Destinat=C3=A4r=20m?= =?UTF-8?q?odel=20(STI-86)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds optional salutation (Herr/Frau/Divers) to the Destinatär model with migration, form support, admin integration and template display. Co-Authored-By: Claude Sonnet 4.6 --- app/stiftung/admin/destinataere.py | 2 +- app/stiftung/forms/destinataere.py | 10 +++------- .../0063_add_anrede_to_destinataer.py | 18 ++++++++++++++++++ app/stiftung/models/destinataere.py | 13 +++++++++++++ app/templates/stiftung/destinataer_detail.html | 12 ++++++++++++ app/templates/stiftung/destinataer_form.html | 7 +++++++ 6 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 app/stiftung/migrations/0063_add_anrede_to_destinataer.py diff --git a/app/stiftung/admin/destinataere.py b/app/stiftung/admin/destinataere.py index 8d67b78..673cee3 100644 --- a/app/stiftung/admin/destinataere.py +++ b/app/stiftung/admin/destinataere.py @@ -24,7 +24,7 @@ class DestinataerAdmin(admin.ModelAdmin): fieldsets = ( ( "Persönliche Daten", - {"fields": ("vorname", "nachname", "geburtsdatum", "email", "telefon")}, + {"fields": ("anrede", "vorname", "nachname", "geburtsdatum", "email", "telefon")}, ), ( "Berufliche Informationen", diff --git a/app/stiftung/forms/destinataere.py b/app/stiftung/forms/destinataere.py index ceb989b..a37a948 100644 --- a/app/stiftung/forms/destinataere.py +++ b/app/stiftung/forms/destinataere.py @@ -54,18 +54,14 @@ class DestinataerForm(forms.ModelForm): for field_name, field in self.fields.items(): if field_name not in ["vorname", "nachname"]: field.required = False - # Set choices for familienzweig and berufsgruppe to match model + # Set choices for familienzweig, berufsgruppe and anrede to match model self.fields["familienzweig"].choices = [("", "Bitte wählen...")] + list(Destinataer.FAMILIENZWIG_CHOICES) self.fields["berufsgruppe"].choices = [("", "Bitte wählen...")] + list(Destinataer.BERUFSGRUPPE_CHOICES) + if "anrede" in self.fields: + self.fields["anrede"].choices = [("", "Bitte wählen...")] + list(Destinataer.ANREDE_CHOICES) # Set choices for standard_konto to allow blank self.fields["standard_konto"].empty_label = "---" - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - for field_name, field in self.fields.items(): - if field_name not in ["vorname", "nachname"]: - field.required = False - class DestinataerUnterstuetzungForm(forms.ModelForm): """Form für geplante/ausgeführte Destinatärunterstützungen""" diff --git a/app/stiftung/migrations/0063_add_anrede_to_destinataer.py b/app/stiftung/migrations/0063_add_anrede_to_destinataer.py new file mode 100644 index 0000000..fa16786 --- /dev/null +++ b/app/stiftung/migrations/0063_add_anrede_to_destinataer.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.6 on 2026-03-21 21:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('stiftung', '0062_veranstaltungseinladung_vorlage'), + ] + + operations = [ + migrations.AddField( + model_name='destinataer', + name='anrede', + field=models.CharField(blank=True, choices=[('Herr', 'Herr'), ('Frau', 'Frau'), ('Divers', 'Divers')], max_length=20, null=True, verbose_name='Anrede'), + ), + ] diff --git a/app/stiftung/models/destinataere.py b/app/stiftung/models/destinataere.py index 190990f..ba716dc 100644 --- a/app/stiftung/models/destinataere.py +++ b/app/stiftung/models/destinataere.py @@ -26,7 +26,20 @@ class Destinataer(models.Model): ("andere", "Andere"), ] + ANREDE_CHOICES = [ + ("Herr", "Herr"), + ("Frau", "Frau"), + ("Divers", "Divers"), + ] + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + anrede = models.CharField( + max_length=20, + choices=ANREDE_CHOICES, + blank=True, + null=True, + verbose_name="Anrede", + ) familienzweig = models.CharField( max_length=100, choices=FAMILIENZWIG_CHOICES, blank=True, null=True ) diff --git a/app/templates/stiftung/destinataer_detail.html b/app/templates/stiftung/destinataer_detail.html index 91faca8..880364a 100644 --- a/app/templates/stiftung/destinataer_detail.html +++ b/app/templates/stiftung/destinataer_detail.html @@ -157,6 +157,18 @@
+ + + +
Anrede + {{ destinataer.anrede|default:"-" }} + +
Vorname diff --git a/app/templates/stiftung/destinataer_form.html b/app/templates/stiftung/destinataer_form.html index 00b33d8..15a7d72 100644 --- a/app/templates/stiftung/destinataer_form.html +++ b/app/templates/stiftung/destinataer_form.html @@ -48,6 +48,13 @@
+ + + +
Anrede + {{ form.anrede }} + {% if form.anrede.errors %}
{{ form.anrede.errors.0 }}
{% endif %} +
Vorname *