35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
"""Tag model: labels that can be linked to accounts/contacts/deals."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import Base, OrgScopedMixin, SoftDeleteMixin, TimestampMixin
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.tag_link import TagLink
|
|
|
|
|
|
class Tag(Base, TimestampMixin, SoftDeleteMixin, OrgScopedMixin):
|
|
__tablename__ = "tags"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
name: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
|
|
color: Mapped[str] = mapped_column(
|
|
String(7), nullable=False, default="#3B82F6", server_default="#3B82F6"
|
|
)
|
|
|
|
# Relationships
|
|
links: Mapped[list[TagLink]] = relationship(
|
|
"TagLink", back_populates="tag", cascade="all, delete-orphan", lazy="selectin"
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Tag id={self.id} name={self.name!r}>"
|
|
|
|
|
|
__all__ = ["Tag"]
|