66 lines
No EOL
2 KiB
Python
66 lines
No EOL
2 KiB
Python
from datetime import date
|
|
from enum import Enum
|
|
from sqlmodel import Field, SQLModel
|
|
|
|
|
|
class BoardgameType(Enum):
|
|
BOARDGAME = 'boardgame'
|
|
BOARDGAMEEXPANSION = 'boardgameexpansion'
|
|
OWNEDBOARDGAME = 'ownedboardgame'
|
|
OWNEDBOARDGAMEEXPANSION = 'ownedboardgameexpansion'
|
|
WISHLISTBOARDGAME = 'wishlistboardgame'
|
|
WISHLISTBOARDGAMEEXPANSION = 'wishlistboardgameexpansion'
|
|
|
|
|
|
class BoardGameBase(SQLModel):
|
|
name: str
|
|
description: str
|
|
weight: float
|
|
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
|
|
|
|
model_config = {
|
|
'validate_assignment':True
|
|
}
|
|
|
|
class OwnedBoardGameBase(BoardGameBase):
|
|
price_paid: float
|
|
acquisition_date: date
|
|
acquired_from: str
|
|
|
|
class WishlistBoardGameBase(BoardGameBase):
|
|
wishlist_priority: int
|
|
|
|
|
|
class BoardGame(BoardGameBase, table=True):
|
|
id: int = Field(primary_key=True)
|
|
type: BoardgameType = BoardgameType.BOARDGAME
|
|
|
|
class BoardGameExpansion(BoardGameBase, table=True):
|
|
id: int = Field(primary_key=True)
|
|
expansion_for: int = Field(default=None, foreign_key="boardgame.id")
|
|
type: BoardgameType = BoardgameType.BOARDGAMEEXPANSION
|
|
|
|
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 |