36 lines
1021 B
Python
36 lines
1021 B
Python
from typing import Optional, List, TYPE_CHECKING
|
|
|
|
from sqlmodel import SQLModel, Field, Relationship
|
|
from app.db.base_class import Base
|
|
|
|
from app.models.matchdayplayer import MatchdayPlayerLink
|
|
from app.models.teamplayers import TeamPlayerLink
|
|
|
|
if TYPE_CHECKING:
|
|
from 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"]
|
|
|