- def from_table_row(cls, row: Row):
- """Make Day from database row."""
- return cls(row[0], row[1])
+ def from_table_row(cls, db_conn: DatabaseConnection, row: Row | list[Any]
+ ) -> Day:
+ """Make from DB row, with linked Todos."""
+ day = super().from_table_row(db_conn, row)
+ assert isinstance(day.id_, str)
+ day.todos = Todo.by_date(db_conn, day.id_)
+ return day
+
+ @classmethod
+ def by_id(cls, db_conn: DatabaseConnection, id_: str) -> Day:
+ """Extend BaseModel.by_id
+
+ Checks Todo.days_to_update if we need to a retrieved Day's .todos,
+ and also ensures we're looking for proper dates and not strings like
+ "yesterday" by enforcing the valid_date translation.
+ """
+ assert isinstance(id_, str)
+ possibly_translated_date = valid_date(id_)
+ day = super().by_id(db_conn, possibly_translated_date)
+ if day.id_ in Todo.days_to_update:
+ Todo.days_to_update.remove(day.id_)
+ day.todos = Todo.by_date(db_conn, day.id_)
+ return day