activity_mtm_week = Table(
"activity_mtm_week",
Base.metadata,
Column("activity_id", ForeignKey("activity.id"), primary_key=True),
Column("week_id", ForeignKey("week.id"), primary_key=True),
)
class Activity(Base):
__tablename__ = "activity"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(15))
weeks: Mapped[List["Week"]] = relationship(
secondary=activity_mtm_week, back_populates="activities"
)
activity_days: Mapped[List["Activity_day"]] = relationship(
cascade="all, delete, delete-orphan"
)
class Week(Base):
__tablename__ = "week"
id: Mapped[int] = mapped_column(primary_key=True)
week_day: Mapped[str] = mapped_column(String(2))
activities: Mapped[List["Activity"]] = relationship(
secondary=activity_mtm_week, back_populates="weeks"
)
class Activity_day(Base):
__tablename__ = "activity_day"
id: Mapped[int] = mapped_column(primary_key=True)
is_done: Mapped[bool] = mapped_column(Boolean, default=False)
day: Mapped[datetime.date] = mapped_column(Date)
activity_id: Mapped[int] = mapped_column(ForeignKey("activity.id"))
There is activity, it has a binding on what days of the week it should be. Activities for the day are created, you can delete them, and the binding to the days of the week must change. You need to create Activity_day for the next week or you need to do this a year in advance and when changing days of the week, change all dates in the future. What’s the best way to do this? Or create tasks every week not next week
I show the user a weekly period, but do not show future days of the week. When I delete an Activity_day in the current week, I delete it from the activity_mtm_week connection. I create the next week based on the activity_mtm_week table. I don’t know if this is a good approach or not.
Kazykan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.