Created Play and PlayPlayer tables with link table
This commit is contained in:
parent
bb1f255c6c
commit
2b7fcdbae3
2 changed files with 21 additions and 7 deletions
|
|
@ -1,18 +1,27 @@
|
|||
from pydantic import BaseModel
|
||||
from sqlmodel import Field, SQLModel, Relationship
|
||||
|
||||
from typing import Union
|
||||
from datetime import date
|
||||
|
||||
class PlayPlayer(BaseModel):
|
||||
name: str
|
||||
class PlayerPlayLink(SQLModel, table=True):
|
||||
player_name: str | None = Field(default=None, foreign_key="playplayer.name", primary_key=True)
|
||||
play_id: int | None = Field(default=None, foreign_key="play.id", primary_key=True)
|
||||
|
||||
class PlayPlayer(SQLModel, table=True):
|
||||
name: str | None = Field(default=None, primary_key=True)
|
||||
username: str
|
||||
score: Union[float, None]
|
||||
first_play : bool
|
||||
has_won : bool
|
||||
|
||||
class Play(BaseModel):
|
||||
plays: list["Play"] = Relationship(back_populates="players", link_model=PlayerPlayLink)
|
||||
|
||||
class Play(SQLModel, table=True):
|
||||
id: int| None = Field(default=None, primary_key=True)
|
||||
boardgame_id: int
|
||||
players: list[PlayPlayer]
|
||||
play_date: date
|
||||
duration: int #In minutes
|
||||
ignore_for_stats : bool
|
||||
location: str
|
||||
|
||||
players: list[PlayPlayer] = Relationship(back_populates="plays", link_model=PlayerPlayLink)
|
||||
|
|
@ -2,7 +2,7 @@ from sqlmodel import create_engine, SQLModel, Session, select
|
|||
from src.config import definitions
|
||||
from typing import Union
|
||||
|
||||
from src.classes import boardgame_classes
|
||||
from src.classes import boardgame_classes, play_classes
|
||||
|
||||
sqlite_url = definitions.SQLITE_URL
|
||||
|
||||
|
|
@ -53,6 +53,11 @@ def delete_database():
|
|||
boardgame_classes.WishlistBoardGame.__table__.drop(engine)
|
||||
boardgame_classes.WishlistBoardGameExpansion.__table__.drop(engine)
|
||||
|
||||
play_classes.Play.__table__.drop(engine)
|
||||
play_classes.PlayPlayer.__table__.drop(engine)
|
||||
play_classes.PlayerPlayLink.__table__.drop(engine)
|
||||
|
||||
|
||||
|
||||
def create_db_and_tables():
|
||||
SQLModel.metadata.create_all(engine)
|
||||
Loading…
Reference in a new issue