mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-09 22:00:18 -04:00
Update entities and models for resource/service tagging
This commit is contained in:
parent
68f07b8c53
commit
21167f7a6b
|
@ -64,4 +64,5 @@ class ResourceEntity(EntityBase):
|
|||
summary=self.summary,
|
||||
link=self.link,
|
||||
program=self.program,
|
||||
tags=[tag.tag.to_model() for tag in self.resourceTags],
|
||||
)
|
||||
|
|
|
@ -15,6 +15,8 @@ from datetime import datetime
|
|||
# Import self for to model
|
||||
from typing import Self
|
||||
|
||||
from ..models import ResourceTag
|
||||
|
||||
|
||||
class ResourceTagEntity(EntityBase):
|
||||
|
||||
|
@ -30,13 +32,13 @@ class ResourceTagEntity(EntityBase):
|
|||
resource: Mapped["ResourceEntity"] = relationship(back_populates="resourceTags")
|
||||
tag: Mapped["TagEntity"] = relationship(back_populates="resourceTags")
|
||||
|
||||
# @classmethod
|
||||
# def from_model (cls, model: resource_tag_model) -> Self:
|
||||
# return cls (
|
||||
# id = model.id,
|
||||
# resourceId = model.resourceId,
|
||||
# tagId = model.tagId,
|
||||
# )
|
||||
@classmethod
|
||||
def from_model(cls, model: ResourceTag) -> Self:
|
||||
return cls(
|
||||
id=model.id,
|
||||
resourceId=model.resource_id,
|
||||
tagId=model.tag_id,
|
||||
)
|
||||
|
||||
# def to_model (self) -> resource_tag_model:
|
||||
# return user_model(
|
||||
|
|
|
@ -16,22 +16,25 @@ from ..models.tag_model import Tag
|
|||
|
||||
from typing import Self
|
||||
|
||||
|
||||
class TagEntity(EntityBase):
|
||||
|
||||
#set table name
|
||||
# set table name
|
||||
__tablename__ = "tag"
|
||||
|
||||
#set fields
|
||||
# set fields
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now)
|
||||
content: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
|
||||
#relationships
|
||||
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(back_populates="tag", cascade="all,delete")
|
||||
serviceTags: Mapped[list["ServiceTagEntity"]] = relationship(back_populates="tag", cascade="all,delete")
|
||||
# relationships
|
||||
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(
|
||||
back_populates="tag", cascade="all,delete"
|
||||
)
|
||||
serviceTags: Mapped[list["ServiceTagEntity"]] = relationship(
|
||||
back_populates="tag", cascade="all,delete"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_model(cls, model: Tag) -> Self:
|
||||
"""
|
||||
|
@ -42,10 +45,10 @@ class TagEntity(EntityBase):
|
|||
Returns:
|
||||
self: The entity
|
||||
"""
|
||||
|
||||
|
||||
return cls(
|
||||
id=model.id,
|
||||
content=model.id,
|
||||
content=model.content,
|
||||
)
|
||||
|
||||
def to_model(self) -> Tag:
|
||||
|
@ -60,6 +63,3 @@ class TagEntity(EntityBase):
|
|||
id=self.id,
|
||||
content=self.content,
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from typing import List
|
|||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from .enum_for_models import ProgramTypeEnum
|
||||
from .tag_model import Tag
|
||||
|
||||
|
||||
class Resource(BaseModel):
|
||||
|
@ -13,3 +14,4 @@ class Resource(BaseModel):
|
|||
link: str = Field(..., max_length=150, description="link to the resource")
|
||||
program: ProgramTypeEnum
|
||||
created_at: Optional[datetime]
|
||||
tags: List[Tag] = []
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
from pydantic import BaseModel, Field
|
||||
from enum import Enum
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from .tag_model import Tag
|
||||
from .resource_model import Resource
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class ResourceTag(Resource, BaseModel):
|
||||
class ResourceTag(BaseModel):
|
||||
id: int | None = None
|
||||
resourceid: int | None = None
|
||||
tagid: List[Tag]
|
||||
tag_id: int
|
||||
resource_id: int
|
||||
|
|
Loading…
Reference in New Issue
Block a user