Better age check

This commit is contained in:
2018-05-03 16:35:40 +02:00
parent 4f61b1e73b
commit 65b8208987

View File

@@ -49,10 +49,12 @@ class MembershipForm(forms.ModelForm):
self.add_error(fieldname, errormsg) self.add_error(fieldname, errormsg)
if membership and cleaned_data.get('birthday'): if membership and cleaned_data.get('birthday'):
birthday = cleaned_data.get('birthday') birthday = cleaned_data.get('birthday')
print("Today:", date.today()) today = date.today()
print("Birthday:", birthday) age = today.year - birthday.year - (
if date.today().year - cleaned_data.get('birthday').year < 16: (today.month, today.day) < (birthday.month, birthday.day))
self.add_error('birthday', 'Midestalter für Mitlieder ist 16 Jahre!') if age < 16:
self.add_error('birthday',
'Midestalter für Mitlieder ist 16 Jahre!')
class RegistrationForm(MembershipForm): class RegistrationForm(MembershipForm):