floorball_stas/app/models/matchday.py

37 lines
913 B
Python

from datetime import date, datetime
from typing import List, Optional, TYPE_CHECKING
from sqlalchemy import Date
from sqlmodel import SQLModel, Relationship, Field, Column, func
from app.db.base_class import Base
from app.models.matchdayplayer import MatchdayPlayerLink
if TYPE_CHECKING:
from app.models.player import Player
class MatchdayBase(SQLModel):
day: date
class Matchday(MatchdayBase, Base, table=True):
day: date = Field(
default=None,
sa_column=Column(Date, server_default=func.now()))
players: List["Player"] = Relationship(back_populates="matchdays",
link_model=MatchdayPlayerLink)
class MatchdayCreate(MatchdayBase):
day: date
class MatchdayUpdate(MatchdayBase):
day: date
class MatchdayWithPlayers(MatchdayBase):
day: date
players: Optional[List["Player"]]