Files
Danilo Reyes ff1c29c66a fix part 3
2025-11-02 18:32:20 -06:00

48 lines
1.7 KiB
Python

"""Group database model."""
from datetime import datetime
from typing import TYPE_CHECKING
from uuid import UUID, uuid4
from sqlalchemy import DateTime, ForeignKey, String, Text, func
from sqlalchemy.dialects.postgresql import UUID as PGUUID
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database.base import Base
if TYPE_CHECKING:
from app.database.models.board import Board
from app.database.models.board_image import BoardImage
class Group(Base):
"""
Group model for organizing images with labels and annotations.
Groups contain multiple images that can be moved together and have
shared visual indicators (color, annotation text).
"""
__tablename__ = "groups"
id: Mapped[UUID] = mapped_column(PGUUID(as_uuid=True), primary_key=True, default=uuid4)
board_id: Mapped[UUID] = mapped_column(
PGUUID(as_uuid=True), ForeignKey("boards.id", ondelete="CASCADE"), nullable=False
)
name: Mapped[str] = mapped_column(String(255), nullable=False)
color: Mapped[str] = mapped_column(String(7), nullable=False) # Hex color #RRGGBB
annotation: Mapped[str | None] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(
DateTime, nullable=False, server_default=func.now(), onupdate=func.now()
)
# Relationships
board: Mapped["Board"] = relationship("Board", back_populates="groups")
board_images: Mapped[list["BoardImage"]] = relationship("BoardImage", back_populates="group")
def __repr__(self) -> str:
"""String representation of Group."""
return f"<Group(id={self.id}, name='{self.name}', board_id={self.board_id})>"