resource, resource_tag to/from models and programtype enum

This commit is contained in:
Jordweinstein 2024-03-25 18:56:12 -04:00
parent f96beee4b2
commit 9cd703d29f
2 changed files with 30 additions and 0 deletions

View File

View File

@ -33,6 +33,36 @@ class ResourceEntity(EntityBase):
#relationships
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(back_populates="resource", cascade="all,delete")
@classmethod
def from_model(cls, model: user_model) -> Self:
"""
Create a UserEntity from a User model.
Args:
model (User): The model to create the entity from.
Returns:
Self: The entity (not yet persisted).
"""
return cls (
id = model.id
created_at = model.created_at
name = model.name
summary = model.summary
link = model.link
program = model.program
)
def to_model(self) -> user_model:
return user_model (
id = self.id
created_at = self.created_at
name = self.name
summary = self.summary
link = self.link
program = self.program
)