added computed underage field
This commit is contained in:
parent
c69c4ad2a2
commit
0de16c68f1
@ -1,5 +1,6 @@
|
||||
from pydantic import model_validator, EmailStr, Field
|
||||
from pydantic import model_validator, EmailStr, Field, computed_field
|
||||
from typing import Self, Literal
|
||||
from datetime import date
|
||||
|
||||
from fiber_package.base import FiberBaseModel
|
||||
from .enums import Membership, LanguageOption
|
||||
@ -20,6 +21,20 @@ class PersonModel(FiberBaseModel):
|
||||
# TODO: phone number
|
||||
address: Address | None = None
|
||||
|
||||
date_of_birth: date | None = None
|
||||
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
def underage(self) -> bool:
|
||||
if self.date_of_birth is None:
|
||||
return False
|
||||
age = ( today.year - self.date_of_birth.year
|
||||
- ( (today.month, today.day)
|
||||
< (self.date_of_birth.month, self.date_of_birth.day) )
|
||||
)
|
||||
return age < 18
|
||||
|
||||
@model_validator(mode="after")
|
||||
def generate_full_name(self) -> Self:
|
||||
full_name = self.first_name
|
||||
@ -28,4 +43,3 @@ class PersonModel(FiberBaseModel):
|
||||
full_name += " " + self.last_name
|
||||
self.full_name = full_name
|
||||
return self
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user