From 5affdb0f5cd3f118908dc1440fcff235c7736461 Mon Sep 17 00:00:00 2001 From: Christian Berg Date: Thu, 3 May 2018 16:35:40 +0200 Subject: [PATCH] Better age check --- src/membership/forms.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/membership/forms.py b/src/membership/forms.py index cf92d96..c685344 100644 --- a/src/membership/forms.py +++ b/src/membership/forms.py @@ -49,10 +49,12 @@ class MembershipForm(forms.ModelForm): self.add_error(fieldname, errormsg) if membership and cleaned_data.get('birthday'): birthday = cleaned_data.get('birthday') - print("Today:", date.today()) - print("Birthday:", birthday) - if date.today().year - cleaned_data.get('birthday').year < 16: - self.add_error('birthday', 'Midestalter für Mitlieder ist 16 Jahre!') + today = date.today() + age = today.year - birthday.year - ( + (today.month, today.day) < (birthday.month, birthday.day)) + if age < 16: + self.add_error('birthday', + 'Midestalter für Mitlieder ist 16 Jahre!') class RegistrationForm(MembershipForm):