diff --git a/aleksis/core/models.py b/aleksis/core/models.py index efabc41dd8643b2a84ce0925abf1d9eddd894109..63cce1c761fa72fe027dcaddedc815ebd247b1df 100644 --- a/aleksis/core/models.py +++ b/aleksis/core/models.py @@ -181,12 +181,13 @@ class Person(ExtensibleModel): return self.age_at(timezone.datetime.now().date()) def age_at(self, today): - years = today.year - self.date_of_birth.year - if (self.date_of_birth.month > today.month - or (self.date_of_birth.month == today.month - and self.date_of_birth.day > today.day)): - years -= 1 - return years + if self.date_of_birth: + years = today.year - self.date_of_birth.year + if (self.date_of_birth.month > today.month + or (self.date_of_birth.month == today.month + and self.date_of_birth.day > today.day)): + years -= 1 + return years def save(self, *args, **kwargs): super().save(*args, **kwargs)