from sqlmodel import Field, SQLModel, Relationship from typing import Union from datetime import date class PlayPlayerBase(SQLModel): username: str score: Union[float, None] first_play : bool has_won : bool play_id : int = Field(default=None, foreign_key="play.id") class PlayPlayer(PlayPlayerBase, table=True): id: int | None = Field(default=None, primary_key=True) name: str = Field(default=None, foreign_key="player.name") play: "Play" = Relationship(back_populates="players") player: "Player" = Relationship(back_populates="playplayers") class PlayPlayerPublic(PlayPlayerBase): id: int name: str player: "PlayerPublicNoPlayPlayers" class PlayPlayerPublicWithPlay(PlayPlayerPublic): name: str play: "PlayPublic" class PlayBase(SQLModel): boardgame_id: int | None = Field(default=None, foreign_key="boardgame.id") play_date: date duration: int #In minutes ignore_for_stats : bool location: str class Play(PlayBase, table=True): id: int | None = Field(default=None, primary_key=True) players: list[PlayPlayer] = Relationship(back_populates="play") boardgame: "BoardGame" = Relationship(back_populates="plays") model_config = { 'validate_assignment':True } class PlayPublic(PlayBase): players: list[PlayPlayerPublic] boardgame: "BoardGamePublicNoPlays" class PlayPublicNoGame(PlayBase): players: list[PlayPlayerPublic] = [] from src.classes.boardgame_classes import BoardGame, BoardGamePublicNoPlays from src.classes.player_classes import Player, PlayerPublic, PlayerPublicNoPlayPlayers Play.model_rebuild()