From c5bdc80c543e382b5d0e42f8839aacbc19562b5f Mon Sep 17 00:00:00 2001 From: Oliver Zander Date: Thu, 16 Oct 2025 16:44:00 +0200 Subject: [PATCH] allow empty grant fields in project --- input/admin.py | 13 +++++++++ .../0104_alter_project_required_fields.py | 28 +++++++++++++++++++ input/models.py | 5 ++-- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 input/migrations/0104_alter_project_required_fields.py diff --git a/input/admin.py b/input/admin.py index b545c0b..aa9e9ea 100755 --- a/input/admin.py +++ b/input/admin.py @@ -86,6 +86,19 @@ class ProjectAdminForm(BaseProjectForm): if self.initial[f'{field}_other']: self.initial[field] = [*self.initial[field], model.other] + def clean(self): + cleaned_data = BaseProjectForm.clean(self) + + if self.errors: + return cleaned_data + + if cleaned_data['granted']: + for field in 'granted_date', 'granted_from', 'account': + if not cleaned_data[field]: + self.add_error(field, 'Dieses Feld ist erforderlich, um dieses Projekt zu bewilligen.') + + return cleaned_data + @admin.register(Project) class ProjectAdmin(admin.ModelAdmin): diff --git a/input/migrations/0104_alter_project_required_fields.py b/input/migrations/0104_alter_project_required_fields.py new file mode 100644 index 0000000..ee08855 --- /dev/null +++ b/input/migrations/0104_alter_project_required_fields.py @@ -0,0 +1,28 @@ +# Generated by Django 5.2.5 on 2025-10-16 14:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('input', '0103_add_request_url'), + ] + + operations = [ + migrations.AlterField( + model_name='project', + name='account', + field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=models.CASCADE, to='input.account'), + ), + migrations.AlterField( + model_name='project', + name='granted_date', + field=models.DateField(blank=True, null=True, verbose_name='Bewilligt am'), + ), + migrations.AlterField( + model_name='project', + name='granted_from', + field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Bewilligt von'), + ), + ] diff --git a/input/models.py b/input/models.py index 3622a04..567e675 100755 --- a/input/models.py +++ b/input/models.py @@ -219,8 +219,9 @@ class Project(Volunteer): insurance_technic = models.BooleanField(default=False, verbose_name='Technikversicherung Ausland') support = models.CharField(max_length=300, blank=True, null=True, verbose_name='Betreuungsperson und Vertretung') cost = models.IntegerField(blank=True, null=True, verbose_name='Kosten') - account = models.ForeignKey('Account', on_delete=models.CASCADE, null=True, to_field='code', db_constraint=False) - granted_from = models.CharField(max_length=100, null=True, verbose_name='Bewilligt von') + account = models.ForeignKey('Account', on_delete=models.CASCADE, blank=True, null=True, to_field='code', db_constraint=False) + granted_date = models.DateField(blank=True, null=True, verbose_name='Bewilligt am') + granted_from = models.CharField(max_length=100, blank=True, null=True, verbose_name='Bewilligt von') notes = models.TextField(max_length=1000, null=True, blank=True, verbose_name='Anmerkungen') intern_notes = models.TextField(max_length=1000, blank=True, verbose_name='interne Anmerkungen')