2024-08-11 20:21:54 +02:00
|
|
|
from sqlmodel import Field, SQLModel, Relationship
|
2024-08-02 12:48:35 +02:00
|
|
|
from typing import Union
|
2024-08-02 11:43:30 +02:00
|
|
|
from datetime import date
|
|
|
|
|
|
2024-08-12 12:08:08 +02:00
|
|
|
class PlayPlayerBase(SQLModel):
|
2024-08-11 21:27:59 +02:00
|
|
|
name: str
|
2024-08-02 11:43:30 +02:00
|
|
|
username: str
|
2024-08-02 12:48:35 +02:00
|
|
|
score: Union[float, None]
|
2024-08-02 11:51:25 +02:00
|
|
|
first_play : bool
|
|
|
|
|
has_won : bool
|
2024-08-11 21:27:59 +02:00
|
|
|
play_id : int = Field(default=None, foreign_key="play.id")
|
2024-08-11 20:21:54 +02:00
|
|
|
|
2024-08-12 12:08:08 +02:00
|
|
|
|
|
|
|
|
class PlayPlayer(PlayPlayerBase, table=True):
|
2024-08-11 21:27:59 +02:00
|
|
|
id: int | None = Field(default=None, primary_key=True)
|
2024-08-12 12:08:08 +02:00
|
|
|
|
|
|
|
|
play: "Play" = Relationship(back_populates="players")
|
|
|
|
|
|
|
|
|
|
class PlayPlayerPublic(PlayPlayerBase):
|
|
|
|
|
id: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PlayPlayerPublicWithPlay(PlayPlayerPublic):
|
|
|
|
|
play: "PlayPublic"
|
|
|
|
|
|
2024-08-12 20:11:34 +02:00
|
|
|
|
2024-08-12 12:08:08 +02:00
|
|
|
class PlayBase(SQLModel):
|
2024-08-12 20:11:34 +02:00
|
|
|
boardgame_id: int | None = Field(default=None, foreign_key="boardgame.id")
|
|
|
|
|
expansion_id: int | None = Field(default=None, foreign_key="boardgameexpansion.id")
|
2024-08-02 12:48:35 +02:00
|
|
|
play_date: date
|
2024-08-02 11:43:30 +02:00
|
|
|
duration: int #In minutes
|
|
|
|
|
ignore_for_stats : bool
|
2024-08-11 20:21:54 +02:00
|
|
|
location: str
|
|
|
|
|
|
2024-08-12 12:08:08 +02:00
|
|
|
|
|
|
|
|
class Play(PlayBase, table=True):
|
|
|
|
|
id: int | None = Field(default=None, primary_key=True)
|
|
|
|
|
|
2024-08-11 21:45:27 +02:00
|
|
|
players: list[PlayPlayer] = Relationship(back_populates="play")
|
2024-08-12 20:11:34 +02:00
|
|
|
boardgame: Union["BoardGame", None] = Relationship(back_populates="plays")
|
2024-08-13 10:35:25 +02:00
|
|
|
boardgameexpansion: Union["BoardGameExpansion", None] = Relationship(back_populates="plays")
|
2024-08-11 21:45:27 +02:00
|
|
|
|
2024-08-12 12:08:08 +02:00
|
|
|
model_config = {
|
2024-08-11 21:45:27 +02:00
|
|
|
'validate_assignment':True
|
|
|
|
|
}
|
2024-08-12 12:08:08 +02:00
|
|
|
|
|
|
|
|
class PlayPublic(PlayBase):
|
|
|
|
|
id: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PlayPublicWithPlayers(PlayPublic):
|
2024-08-12 20:11:34 +02:00
|
|
|
players: list[PlayPlayerPublic] = []
|
|
|
|
|
boardgame: Union["BoardGameNoPlays", None]
|
2024-08-13 10:35:25 +02:00
|
|
|
boardgameexpansion: Union["BoardGameExpansionNoPlays", None]
|
2024-08-12 20:11:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
from src.classes.boardgame_classes import BoardGame, BoardGameExpansion, BoardGameNoPlays, BoardGameExpansionNoPlays
|
2024-08-19 13:50:27 +02:00
|
|
|
from src.classes.people_classes import Designer
|
2024-08-12 20:11:34 +02:00
|
|
|
Play.model_rebuild()
|
|
|
|
|
PlayPublicWithPlayers.model_rebuild()
|