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"
|
|
|
|
|
|
|
|
|
|
class PlayBase(SQLModel):
|
2024-08-02 11:43:30 +02:00
|
|
|
boardgame_id: int
|
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 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):
|
|
|
|
|
players: list[PlayPlayerPublic] = []
|