28 lines
910 B
Python
28 lines
910 B
Python
from datetime import date as date_type, datetime
|
|
from typing import TYPE_CHECKING, List, Optional
|
|
|
|
from sqlalchemy import Date, DateTime, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.core.database.models.base import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from app.core.database.models.exercise import ExerciseModel
|
|
|
|
|
|
class TrainingModel(Base):
|
|
__tablename__ = "trainings"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
date: Mapped[date_type] = mapped_column(Date, index=True)
|
|
trainer: Mapped[Optional[str]] = mapped_column(String(100))
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now()
|
|
)
|
|
|
|
exercises: Mapped[List["ExerciseModel"]] = relationship(
|
|
back_populates="training",
|
|
cascade="all, delete-orphan",
|
|
passive_deletes=True,
|
|
order_by="ExerciseModel.id",
|
|
)
|