33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from datetime import datetime
|
|
from typing import TYPE_CHECKING, List
|
|
|
|
from sqlalchemy import Boolean, DateTime, ForeignKey, 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.approach import ApproachModel
|
|
from app.core.database.models.training import TrainingModel
|
|
|
|
|
|
class ExerciseModel(Base):
|
|
__tablename__ = "exercises"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
training_id: Mapped[int] = mapped_column(
|
|
ForeignKey("trainings.id", ondelete="CASCADE"), index=True
|
|
)
|
|
name: Mapped[str] = mapped_column(String(255), index=True)
|
|
splitted_weight: Mapped[bool] = mapped_column(Boolean, server_default="false")
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now()
|
|
)
|
|
|
|
training: Mapped["TrainingModel"] = relationship(back_populates="exercises")
|
|
approaches: Mapped[List["ApproachModel"]] = relationship(
|
|
back_populates="exercise",
|
|
cascade="all, delete-orphan",
|
|
passive_deletes=True,
|
|
order_by="ApproachModel.id",
|
|
)
|