Skip to content
Snippets Groups Projects
Commit 23d2c21d authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch '220-add-age_at-method-and-age-property' into 'master'

Resolve "Add age_at method and age property"

Closes #220

See merge request AlekSIS!212
parents e121831e f70c1d93
No related branches found
No related tags found
1 merge request!212Resolve "Add age_at method and age property"
Pipeline #1291 failed
......@@ -168,6 +168,18 @@ class Person(ExtensibleModel):
else:
return f"{self.first_name} {self.last_name}"
@property
def age(self):
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
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment