2024-08-01 11:48:29 +02:00
|
|
|
from datetime import date
|
2024-08-01 12:05:51 +02:00
|
|
|
from enum import Enum
|
2024-08-21 21:03:49 +02:00
|
|
|
from typing import Optional
|
2024-08-12 20:11:34 +02:00
|
|
|
from sqlmodel import Field, SQLModel, Relationship
|
2024-08-19 13:50:27 +02:00
|
|
|
from src.classes import many_to_many_links
|
2024-08-03 15:42:19 +02:00
|
|
|
|
2024-08-01 12:05:51 +02:00
|
|
|
|
|
|
|
|
class BoardgameType(Enum):
|
2024-08-01 12:16:50 +02:00
|
|
|
BOARDGAME = 'boardgame'
|
|
|
|
|
BOARDGAMEEXPANSION = 'boardgameexpansion'
|
2024-08-02 10:50:18 +02:00
|
|
|
OWNEDBOARDGAME = 'ownedboardgame'
|
|
|
|
|
OWNEDBOARDGAMEEXPANSION = 'ownedboardgameexpansion'
|
2024-08-01 12:16:50 +02:00
|
|
|
WISHLISTBOARDGAME = 'wishlistboardgame'
|
2024-08-02 10:37:47 +02:00
|
|
|
WISHLISTBOARDGAMEEXPANSION = 'wishlistboardgameexpansion'
|
2024-08-01 12:05:51 +02:00
|
|
|
|
2024-07-25 18:01:51 +02:00
|
|
|
|
2024-08-03 15:42:19 +02:00
|
|
|
class BoardGameBase(SQLModel):
|
2024-08-03 14:18:54 +02:00
|
|
|
name: str
|
|
|
|
|
description: str
|
2024-08-08 16:50:42 +02:00
|
|
|
weight: float
|
2024-08-03 14:18:54 +02:00
|
|
|
image_url : str
|
|
|
|
|
thumbnail_url : str
|
|
|
|
|
year_published: int
|
|
|
|
|
min_players: int
|
|
|
|
|
max_players: int
|
|
|
|
|
min_playing_time: int
|
|
|
|
|
max_playing_time: int
|
|
|
|
|
min_age: int
|
|
|
|
|
|
2024-08-03 15:42:19 +02:00
|
|
|
model_config = {
|
|
|
|
|
'validate_assignment':True
|
|
|
|
|
}
|
2024-08-03 14:18:54 +02:00
|
|
|
|
2024-08-21 21:03:49 +02:00
|
|
|
# class OwnedBoardGameBase(BoardGameBase):
|
|
|
|
|
# price_paid: float
|
|
|
|
|
# acquisition_date: date
|
|
|
|
|
# acquired_from: str
|
2024-08-03 15:42:19 +02:00
|
|
|
|
2024-08-21 21:03:49 +02:00
|
|
|
# class WishlistBoardGameBase(BoardGameBase):
|
|
|
|
|
# wishlist_priority: int
|
2024-08-03 15:42:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class BoardGame(BoardGameBase, table=True):
|
|
|
|
|
id: int = Field(primary_key=True)
|
|
|
|
|
type: BoardgameType = BoardgameType.BOARDGAME
|
2024-08-21 21:03:49 +02:00
|
|
|
#plays: list["Play"] = Relationship(back_populates='boardgame')
|
2024-08-19 13:50:27 +02:00
|
|
|
designers: list["Designer"] = Relationship(back_populates="designed_boardgames", link_model=many_to_many_links.DesignerBoardGameLink)
|
2024-08-21 21:03:49 +02:00
|
|
|
expansion_info: Optional["ExpansionInfo"] = Relationship(back_populates="boardgame")
|
|
|
|
|
owned_info: Optional["OwnedInfo"] = Relationship(back_populates="boardgame")
|
|
|
|
|
wishlist_info: Optional["WishlistInfo"] = Relationship(back_populates="boardgame")
|
|
|
|
|
|
|
|
|
|
model_config = {
|
|
|
|
|
'arbitrary_types_allowed':True
|
|
|
|
|
}
|
2024-08-12 20:11:34 +02:00
|
|
|
|
2024-08-18 17:12:19 +02:00
|
|
|
class BoardGamePublic(BoardGameBase):
|
|
|
|
|
id: int
|
2024-08-19 13:50:27 +02:00
|
|
|
designers: list["Designer"]
|
2024-08-21 21:03:49 +02:00
|
|
|
expansion_info: Optional["ExpansionInfo"]
|
|
|
|
|
owned_info: Optional["OwnedInfo"]
|
|
|
|
|
wishlist_info: Optional["WishlistInfo"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExpansionInfo(BoardGameBase, table=True):
|
|
|
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
|
|
|
boardgame_id: int | None = Field(default=None, foreign_key="boardgame.id")
|
|
|
|
|
boardgame: BoardGame = Relationship(
|
|
|
|
|
#for one-on-one relationship
|
|
|
|
|
sa_relationship_kwargs={'uselist': False},
|
|
|
|
|
back_populates="expansion_info"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OwnedInfo(SQLModel, table=True):
|
|
|
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
|
|
|
boardgame_id: int | None = Field(default=None, foreign_key="boardgame.id")
|
|
|
|
|
boardgame: BoardGame = Relationship(
|
|
|
|
|
#for one-on-one relationship
|
|
|
|
|
sa_relationship_kwargs={'uselist': False},
|
|
|
|
|
back_populates="owned_info"
|
|
|
|
|
)
|
|
|
|
|
price_paid: float
|
|
|
|
|
acquisition_date: date
|
|
|
|
|
acquired_from: str
|
2024-08-18 17:12:19 +02:00
|
|
|
|
2024-08-21 21:03:49 +02:00
|
|
|
class WishlistInfo(SQLModel, table=True):
|
|
|
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
|
|
|
boardgame_id: int | None = Field(default=None, foreign_key="boardgame.id")
|
|
|
|
|
boardgame: BoardGame = Relationship(
|
|
|
|
|
#for one-on-one relationship
|
|
|
|
|
sa_relationship_kwargs={'uselist': False},
|
|
|
|
|
back_populates="wishlist_info"
|
|
|
|
|
)
|
|
|
|
|
wishlist_priority: int
|
2024-08-03 15:42:19 +02:00
|
|
|
|
2024-08-12 20:11:34 +02:00
|
|
|
|
2024-08-21 21:03:49 +02:00
|
|
|
# class BoardGamePublic(BoardGameBase):
|
|
|
|
|
# id: int
|
|
|
|
|
# type: BoardgameType
|
|
|
|
|
# plays: list["Play"]
|
|
|
|
|
# designers: list["Designer"]
|
2024-08-18 17:12:19 +02:00
|
|
|
|
2024-08-21 21:03:49 +02:00
|
|
|
# class BoardGameNoPlays(BoardGameBase):
|
|
|
|
|
# id: int
|
|
|
|
|
# designers: list["Designer"]
|
|
|
|
|
# type: BoardgameType = BoardgameType.BOARDGAME
|
2024-08-03 15:42:19 +02:00
|
|
|
|
2024-08-01 11:48:29 +02:00
|
|
|
|
2024-08-21 21:03:49 +02:00
|
|
|
# class BoardGameExpansionPublic(BoardGameBase):
|
|
|
|
|
# id: int
|
|
|
|
|
# expansion_for: int
|
|
|
|
|
# type: BoardgameType
|
|
|
|
|
# plays: list["Play"]
|
|
|
|
|
# designers: list["Designer"]
|
2024-08-01 11:48:29 +02:00
|
|
|
|
2024-08-21 21:03:49 +02:00
|
|
|
# class BoardGameExpansionNoPlays(BoardGameBase):
|
|
|
|
|
# id: int
|
|
|
|
|
# expansion_for: int
|
|
|
|
|
# designers: list["Designer"]
|
|
|
|
|
# type: BoardgameType = BoardgameType.BOARDGAMEEXPANSION
|
2024-08-02 10:37:47 +02:00
|
|
|
|
2024-08-21 21:03:49 +02:00
|
|
|
# class OwnedBoardGame(OwnedBoardGameBase, table=True):
|
|
|
|
|
# id: int = Field(primary_key=True)
|
|
|
|
|
# type: BoardgameType = BoardgameType.OWNEDBOARDGAME
|
|
|
|
|
|
|
|
|
|
# class OwnedBoardGameExpansion(OwnedBoardGameBase, table=True):
|
|
|
|
|
# id: int = Field(primary_key=True)
|
|
|
|
|
# expansion_for: int = Field(default=None, foreign_key="boardgame.id")
|
|
|
|
|
# type: BoardgameType = BoardgameType.OWNEDBOARDGAMEEXPANSION
|
|
|
|
|
|
|
|
|
|
# class WishlistBoardGame(WishlistBoardGameBase, table=True):
|
|
|
|
|
# id: int = Field(primary_key=True)
|
|
|
|
|
# type: BoardgameType = BoardgameType.WISHLISTBOARDGAME
|
|
|
|
|
|
|
|
|
|
# class WishlistBoardGameExpansion(WishlistBoardGameBase, table=True):
|
|
|
|
|
# id: int = Field(primary_key=True)
|
|
|
|
|
# expansion_for: int = Field(default=None, foreign_key="boardgame.id")
|
|
|
|
|
# type: BoardgameType = BoardgameType.WISHLISTBOARDGAMEEXPANSION
|
2024-08-12 20:11:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from src.classes.play_classes import Play, PlayPublic
|
2024-08-19 13:50:27 +02:00
|
|
|
from src.classes.people_classes import Designer
|
2024-08-12 20:11:34 +02:00
|
|
|
BoardGame.model_rebuild()
|
2024-08-21 21:03:49 +02:00
|
|
|
# BoardGameExpansion.model_rebuild()
|
|
|
|
|
# BoardGameNoPlays.model_rebuild()
|
|
|
|
|
# BoardGameExpansionNoPlays.model_rebuild()
|