From b153b78048274f127712fe5063cf3058a69163e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benni=20B=C3=A4rmann?= Date: Tue, 6 Dec 2022 17:39:25 +0000 Subject: [PATCH] added adult multiple choice radio button by changing admin.py and forms.py --- input/admin.py | 1 + input/forms.py | 9 +++++++++ input/models.py | 1 + 3 files changed, 11 insertions(+) diff --git a/input/admin.py b/input/admin.py index ce8fe34..547fc8f 100755 --- a/input/admin.py +++ b/input/admin.py @@ -100,6 +100,7 @@ class EmailAdmin(admin.ModelAdmin): list_display = ('realname', 'service_id', 'granted', 'granted_date') list_display_links = ('realname', 'service_id') date_hierarchy = 'granted_date' + radio_fields = {'adult': admin.VERTICAL} class Media: js = ('dropdown/js/base.js',) diff --git a/input/forms.py b/input/forms.py index 076b099..8b0b898 100755 --- a/input/forms.py +++ b/input/forms.py @@ -114,6 +114,11 @@ class LiteratureForm(CheckForm): class Media: js = ('dropdown/js/literature.js',) +ADULT_CHOICES = {'TRUE': format_html('Ich bin volljährig.'), + 'FALSE': format_html('Ich bin noch nicht volljährig.') + } + + class EmailForm(CheckForm): # this is the code, to change required to false if needed @@ -122,6 +127,10 @@ class EmailForm(CheckForm): self.fields['adult'].required = True self.fields['other'].required = True + adult = ChoiceField(label='Volljährigkeit', choices=ADULT_CHOICES.items(), widget=RadioSelect()) + + + # TODO: add some javascript to show/hide other-field class Meta: model = Email diff --git a/input/models.py b/input/models.py index 30d1c02..8ae7958 100755 --- a/input/models.py +++ b/input/models.py @@ -180,6 +180,7 @@ def getProjectEnd(sender, instance, **kwargs): instance.project_end = instance.project.end +# using pre save instead # def save(self,*args,**kwargs): # '''we generate the autogenerated fields here''' # # we don't call save with args/kwargs to avoid UNIQUE CONSTRAINT errors