Browse Source

added adult multiple choice radio button by changing admin.py and forms.py

master
alpcentaur 1 year ago
parent
commit
e638afabd5
3 changed files with 11 additions and 0 deletions
  1. +1
    -0
      input/admin.py
  2. +9
    -0
      input/forms.py
  3. +1
    -0
      input/models.py

+ 1
- 0
input/admin.py View File

@ -100,6 +100,7 @@ class EmailAdmin(admin.ModelAdmin):
list_display = ('realname', 'service_id', 'granted', 'granted_date') list_display = ('realname', 'service_id', 'granted', 'granted_date')
list_display_links = ('realname', 'service_id') list_display_links = ('realname', 'service_id')
date_hierarchy = 'granted_date' date_hierarchy = 'granted_date'
radio_fields = {'adult': admin.VERTICAL}
class Media: class Media:
js = ('dropdown/js/base.js',) js = ('dropdown/js/base.js',)

+ 9
- 0
input/forms.py View File

@ -114,6 +114,11 @@ class LiteratureForm(CheckForm):
class Media: class Media:
js = ('dropdown/js/literature.js',) 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): class EmailForm(CheckForm):
# this is the code, to change required to false if needed # 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['adult'].required = True
self.fields['other'].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 # TODO: add some javascript to show/hide other-field
class Meta: class Meta:
model = Email model = Email

+ 1
- 0
input/models.py View File

@ -180,6 +180,7 @@ def getProjectEnd(sender, instance, **kwargs):
instance.project_end = instance.project.end instance.project_end = instance.project.end
# using pre save instead
# def save(self,*args,**kwargs): # def save(self,*args,**kwargs):
# '''we generate the autogenerated fields here''' # '''we generate the autogenerated fields here'''
# # we don't call save with args/kwargs to avoid UNIQUE CONSTRAINT errors # # we don't call save with args/kwargs to avoid UNIQUE CONSTRAINT errors

Loading…
Cancel
Save