This is the initial push of the outline of the life dashboard
This commit is contained in:
43
backend/app/models/workout.py
Normal file
43
backend/app/models/workout.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from datetime import date, datetime
|
||||
|
||||
from sqlalchemy import Date, ForeignKey, Integer, Numeric, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Exercise(Base):
|
||||
__tablename__ = "exercises"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(Text, unique=True)
|
||||
category: Mapped[str] = mapped_column(Text)
|
||||
|
||||
|
||||
class Workout(Base):
|
||||
__tablename__ = "workouts"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
date: Mapped[date] = mapped_column(Date)
|
||||
name: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(server_default=func.now())
|
||||
|
||||
sets: Mapped[list["WorkoutSet"]] = relationship(
|
||||
back_populates="workout", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
|
||||
class WorkoutSet(Base):
|
||||
__tablename__ = "workout_sets"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
workout_id: Mapped[int] = mapped_column(ForeignKey("workouts.id", ondelete="CASCADE"))
|
||||
exercise_id: Mapped[int] = mapped_column(ForeignKey("exercises.id"))
|
||||
set_number: Mapped[int] = mapped_column(Integer)
|
||||
reps: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
weight_lbs: Mapped[float | None] = mapped_column(Numeric(6, 1), nullable=True)
|
||||
duration_min: Mapped[float | None] = mapped_column(Numeric(5, 1), nullable=True)
|
||||
|
||||
workout: Mapped["Workout"] = relationship(back_populates="sets")
|
||||
exercise: Mapped["Exercise"] = relationship()
|
||||
Reference in New Issue
Block a user