Files
mealie/mealie/db/models/recipe/ingredient.py
Hayden b57e42a3b3 Fix/incorrect quantity column (#1093)
* change database type

* database migration for changing type on PostgreSQL

* update revision

* add exclusion directory

* update recipe-scrapers
2022-03-27 09:18:34 -08:00

71 lines
2.3 KiB
Python

from sqlalchemy import Boolean, Column, Float, ForeignKey, Integer, String, orm
from mealie.db.models._model_base import BaseMixins, SqlAlchemyBase
from mealie.db.models.labels import MultiPurposeLabel
from .._model_utils import auto_init
from .._model_utils.guid import GUID
class IngredientUnitModel(SqlAlchemyBase, BaseMixins):
__tablename__ = "ingredient_units"
id = Column(GUID, primary_key=True, default=GUID.generate)
# ID Relationships
group_id = Column(GUID, ForeignKey("groups.id"), nullable=False)
group = orm.relationship("Group", back_populates="ingredient_units", foreign_keys=[group_id])
name = Column(String)
description = Column(String)
abbreviation = Column(String)
fraction = Column(Boolean)
ingredients = orm.relationship("RecipeIngredient", back_populates="unit")
@auto_init()
def __init__(self, **_) -> None:
pass
class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
__tablename__ = "ingredient_foods"
id = Column(GUID, primary_key=True, default=GUID.generate)
# ID Relationships
group_id = Column(GUID, ForeignKey("groups.id"), nullable=False)
group = orm.relationship("Group", back_populates="ingredient_foods", foreign_keys=[group_id])
name = Column(String)
description = Column(String)
ingredients = orm.relationship("RecipeIngredient", back_populates="food")
label_id = Column(GUID, ForeignKey("multi_purpose_labels.id"))
label = orm.relationship(MultiPurposeLabel, uselist=False, back_populates="foods")
@auto_init()
def __init__(self, **_) -> None:
pass
class RecipeIngredient(SqlAlchemyBase, BaseMixins):
__tablename__ = "recipes_ingredients"
id = Column(Integer, primary_key=True)
position = Column(Integer)
recipe_id = Column(GUID, ForeignKey("recipes.id"))
title = Column(String) # Section Header - Shows if Present
note = Column(String) # Force Show Text - Overrides Concat
# Scaling Items
unit_id = Column(GUID, ForeignKey("ingredient_units.id"))
unit = orm.relationship(IngredientUnitModel, uselist=False)
food_id = Column(GUID, ForeignKey("ingredient_foods.id"))
food = orm.relationship(IngredientFoodModel, uselist=False)
quantity = Column(Float)
reference_id = Column(GUID) # Reference Links
@auto_init()
def __init__(self, **_) -> None:
pass