mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-05 23:43:11 -05:00
feat: Add the ability to flag a food as "on hand", to exclude from shopping list (#3777)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -36,6 +36,7 @@ class UnitFoodBase(MealieModel):
|
||||
plural_name: str | None = None
|
||||
description: str = ""
|
||||
extras: dict | None = {}
|
||||
on_hand: bool = False
|
||||
|
||||
@field_validator("id", mode="before")
|
||||
def convert_empty_id_to_none(cls, v):
|
||||
@@ -79,13 +80,19 @@ class IngredientFood(CreateIngredientFood):
|
||||
created_at: datetime.datetime | None = None
|
||||
update_at: datetime.datetime | None = None
|
||||
|
||||
_searchable_properties: ClassVar[list[str]] = ["name_normalized", "plural_name_normalized"]
|
||||
_searchable_properties: ClassVar[list[str]] = [
|
||||
"name_normalized",
|
||||
"plural_name_normalized",
|
||||
]
|
||||
_normalize_search: ClassVar[bool] = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@classmethod
|
||||
def loader_options(cls) -> list[LoaderOption]:
|
||||
return [joinedload(IngredientFoodModel.extras), joinedload(IngredientFoodModel.label)]
|
||||
return [
|
||||
joinedload(IngredientFoodModel.extras),
|
||||
joinedload(IngredientFoodModel.label),
|
||||
]
|
||||
|
||||
|
||||
class IngredientFoodPagination(PaginationBase):
|
||||
|
||||
Reference in New Issue
Block a user