floorball_stas/backend/app/models/player.py

36 lines
1.0 KiB
Python

from typing import List, TYPE_CHECKING
from sqlmodel import SQLModel, Field, Relationship
from backend.app.db.base_class import Base
from backend.app.models.matchdayplayer import MatchdayPlayerLink
from backend.app.models.teamplayers import TeamPlayerLink
if TYPE_CHECKING:
from backend.app.models import Team, Matchday
class PlayerBase(SQLModel):
firstname: str = Field(nullable=False)
lastname: str = Field(nullable=False)
class Player(PlayerBase, Base, table=True):
teams: List["Team"] = Relationship(back_populates="players",
link_model=TeamPlayerLink)
matchdays: List["Matchday"] = Relationship(back_populates="players",
link_model=MatchdayPlayerLink)
class PlayerCreate(PlayerBase):
firstname: str
lastname: str
class PlayerUpdate(PlayerBase):
firstname: str
lastname: str
class PlayerTeamsMatchdays(PlayerBase):
matchdays: List["Matchday"]
teams: List["Team"]