feat: Add the ability to flag a food as "on hand", to exclude from shopping list (#3777)

This commit is contained in:
boc-the-git
2024-06-29 01:16:04 +10:00
committed by GitHub
parent 4831adb0f3
commit a062a4beaa
8 changed files with 112 additions and 9 deletions

View File

@@ -36,7 +36,9 @@ class IngredientUnitModel(SqlAlchemyBase, BaseMixins):
"RecipeIngredientModel", back_populates="unit"
)
aliases: Mapped[list["IngredientUnitAliasModel"]] = orm.relationship(
"IngredientUnitAliasModel", back_populates="unit", cascade="all, delete, delete-orphan"
"IngredientUnitAliasModel",
back_populates="unit",
cascade="all, delete, delete-orphan",
)
# Automatically updated by sqlalchemy event, do not write to this manually
@@ -144,12 +146,15 @@ class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
name: Mapped[str | None] = mapped_column(String)
plural_name: Mapped[str | None] = mapped_column(String)
description: Mapped[str | None] = mapped_column(String)
on_hand: Mapped[bool] = mapped_column(Boolean)
ingredients: Mapped[list["RecipeIngredientModel"]] = orm.relationship(
"RecipeIngredientModel", back_populates="food"
)
aliases: Mapped[list["IngredientFoodAliasModel"]] = orm.relationship(
"IngredientFoodAliasModel", back_populates="food", cascade="all, delete, delete-orphan"
"IngredientFoodAliasModel",
back_populates="food",
cascade="all, delete, delete-orphan",
)
extras: Mapped[list[IngredientFoodExtras]] = orm.relationship("IngredientFoodExtras", cascade="all, delete-orphan")
@@ -162,7 +167,13 @@ class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
@api_extras
@auto_init()
def __init__(self, session: Session, name: str | None = None, plural_name: str | None = None, **_) -> None:
def __init__(
self,
session: Session,
name: str | None = None,
plural_name: str | None = None,
**_,
) -> None:
if name is not None:
self.name_normalized = self.normalize(name)
if plural_name is not None:
@@ -317,7 +328,13 @@ class RecipeIngredientModel(SqlAlchemyBase, BaseMixins):
original_text_normalized: Mapped[str | None] = mapped_column(String, index=True)
@auto_init()
def __init__(self, session: Session, note: str | None = None, orginal_text: str | None = None, **_) -> None:
def __init__(
self,
session: Session,
note: str | None = None,
orginal_text: str | None = None,
**_,
) -> None:
# SQLAlchemy events do not seem to register things that are set during auto_init
if note is not None:
self.note_normalized = self.normalize(note)