from datetime import date from typing import List, Optional, TYPE_CHECKING from sqlalchemy import Date from sqlmodel import SQLModel, Relationship, Field, Column, func from backend.app.db.base_class import Base from backend.app.models.matchdayplayer import MatchdayPlayerLink if TYPE_CHECKING: from backend.app.models.player import Player class MatchdayBase(SQLModel): day: date class Matchday(MatchdayBase, Base, table=True): day: date = Field( default=None, sa_column=Column(Date, server_default=func.now())) players: List["Player"] = Relationship(back_populates="matchdays", link_model=MatchdayPlayerLink) class MatchdayCreate(MatchdayBase): day: date class MatchdayUpdate(MatchdayBase): day: date class MatchdayWithPlayers(MatchdayBase): day: date players: Optional[List["Player"]]