bgg_api/src/classes/play_classes.py

50 lines
No EOL
1.1 KiB
Python

from sqlmodel import Field, SQLModel, Relationship
from typing import Union
from datetime import date
class PlayPlayerBase(SQLModel):
name: str
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)
play: "Play" = Relationship(back_populates="players")
class PlayPlayerPublic(PlayPlayerBase):
id: int
class PlayPlayerPublicWithPlay(PlayPlayerPublic):
play: "PlayPublic"
class PlayBase(SQLModel):
boardgame_id: int
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")
model_config = {
'validate_assignment':True
}
class PlayPublic(PlayBase):
id: int
class PlayPublicWithPlayers(PlayPublic):
players: list[PlayPlayerPublic] = []