From 6c276dc596351db79b882c4856a7071e7da34321 Mon Sep 17 00:00:00 2001 From: Thomas Girod Date: Sat, 12 Nov 2022 13:59:58 +0100 Subject: [PATCH] resolved crash when user has no birthdate --- core/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/models.py b/core/models.py index bedba304..e904603f 100644 --- a/core/models.py +++ b/core/models.py @@ -470,7 +470,10 @@ class User(AbstractBaseUser): def age(self) -> int: """ Return the age this user has the day the method is called. + If the user has not filled his age, return 0 """ + if self.date_of_birth is None: + return 0 today = timezone.now() age = today.year - self.date_of_birth.year # remove a year if this year's birthday is yet to come