Last active
May 25, 2019 21:51
-
-
Save fcasco/06ded37f06a3d74a6de74287e210aea0 to your computer and use it in GitHub Desktop.
Extra SQL en Django. 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.utils improt timezone | |
class Person(models.Model): | |
first_name = models.CharField(max_length=42) | |
last_name = models.CharField(max_length=42) | |
birth_date = models.DateField() | |
@property | |
def age(self): | |
now = timezone.now() | |
years = now.year - self.birth_date.year | |
if now.month < self.birth_date.month: | |
age -= 1 | |
elif now.month == self.birth_date.month and now.day < birth_date.day: | |
age -= 1 | |
return age |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment