From 53513546eddffa8a7f1c9182625b2900438cdcb7 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Thu, 4 Jun 2026 00:06:19 +0000 Subject: [PATCH] Upload app/models/tag.py --- app/models/tag.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/models/tag.py diff --git a/app/models/tag.py b/app/models/tag.py new file mode 100644 index 0000000..168f550 --- /dev/null +++ b/app/models/tag.py @@ -0,0 +1,34 @@ +"""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"" + + +__all__ = ["Tag"]