mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
asset start
This commit is contained in:
parent
e6676e2ff8
commit
3d4a29a2bd
3 changed files with 29 additions and 50 deletions
20
mealie/db/models/recipe/assets.py
Normal file
20
mealie/db/models/recipe/assets.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from mealie.db.models.model_base import SqlAlchemyBase
|
||||||
|
|
||||||
|
|
||||||
|
class RecipeAsset(SqlAlchemyBase):
|
||||||
|
__tablename__ = "recipe_assets"
|
||||||
|
id = sa.Column(sa.Integer, primary_key=True)
|
||||||
|
parent_id = sa.Column(sa.String, sa.ForeignKey("recipes.id"))
|
||||||
|
name = sa.Column(sa.String)
|
||||||
|
icon = sa.Column(sa.String)
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name=None,
|
||||||
|
icon=None,
|
||||||
|
) -> None:
|
||||||
|
self.name = name
|
||||||
|
self.icon = icon
|
||||||
|
|
|
@ -6,6 +6,7 @@ import sqlalchemy as sa
|
||||||
import sqlalchemy.orm as orm
|
import sqlalchemy.orm as orm
|
||||||
from mealie.db.models.model_base import BaseMixins, SqlAlchemyBase
|
from mealie.db.models.model_base import BaseMixins, SqlAlchemyBase
|
||||||
from mealie.db.models.recipe.api_extras import ApiExtras
|
from mealie.db.models.recipe.api_extras import ApiExtras
|
||||||
|
from mealie.db.models.recipe.assets import RecipeAsset
|
||||||
from mealie.db.models.recipe.category import Category, recipes2categories
|
from mealie.db.models.recipe.category import Category, recipes2categories
|
||||||
from mealie.db.models.recipe.ingredient import RecipeIngredient
|
from mealie.db.models.recipe.ingredient import RecipeIngredient
|
||||||
from mealie.db.models.recipe.instruction import RecipeInstruction
|
from mealie.db.models.recipe.instruction import RecipeInstruction
|
||||||
|
@ -86,6 +87,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||||
rating: int = None,
|
rating: int = None,
|
||||||
orgURL: str = None,
|
orgURL: str = None,
|
||||||
extras: dict = None,
|
extras: dict = None,
|
||||||
|
assets: list = None,
|
||||||
*args,
|
*args,
|
||||||
**kwargs
|
**kwargs
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -99,6 +101,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||||
|
|
||||||
self.recipeYield = recipeYield
|
self.recipeYield = recipeYield
|
||||||
self.recipeIngredient = [RecipeIngredient(ingredient=ingr) for ingr in recipeIngredient]
|
self.recipeIngredient = [RecipeIngredient(ingredient=ingr) for ingr in recipeIngredient]
|
||||||
|
self.assets = [RecipeAsset(name=a.get("name"), icon=a.get("icon")) for a in assets]
|
||||||
self.recipeInstructions = [
|
self.recipeInstructions = [
|
||||||
RecipeInstruction(text=instruc.get("text"), title=instruc.get("title"), type=instruc.get("@type", None))
|
RecipeInstruction(text=instruc.get("text"), title=instruc.get("title"), type=instruc.get("@type", None))
|
||||||
for instruc in recipeInstructions
|
for instruc in recipeInstructions
|
||||||
|
@ -118,54 +121,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||||
self.orgURL = orgURL
|
self.orgURL = orgURL
|
||||||
self.extras = [ApiExtras(key=key, value=value) for key, value in extras.items()]
|
self.extras = [ApiExtras(key=key, value=value) for key, value in extras.items()]
|
||||||
|
|
||||||
def update(
|
def update(self, *args, **kwargs):
|
||||||
self,
|
|
||||||
session,
|
|
||||||
name: str = None,
|
|
||||||
description: str = None,
|
|
||||||
image: str = None,
|
|
||||||
recipeYield: str = None,
|
|
||||||
recipeIngredient: List[str] = None,
|
|
||||||
recipeInstructions: List[dict] = None,
|
|
||||||
recipeCuisine: str = None,
|
|
||||||
totalTime: str = None,
|
|
||||||
tools: list[str] = [],
|
|
||||||
prepTime: str = None,
|
|
||||||
performTime: str = None,
|
|
||||||
nutrition: dict = None,
|
|
||||||
slug: str = None,
|
|
||||||
recipeCategory: List[str] = None,
|
|
||||||
tags: List[str] = None,
|
|
||||||
dateAdded: datetime.date = None,
|
|
||||||
notes: List[dict] = None,
|
|
||||||
rating: int = None,
|
|
||||||
orgURL: str = None,
|
|
||||||
extras: dict = None,
|
|
||||||
*args,
|
|
||||||
**kwargs
|
|
||||||
):
|
|
||||||
"""Updated a database entry by removing nested rows and rebuilds the row through the __init__ functions"""
|
"""Updated a database entry by removing nested rows and rebuilds the row through the __init__ functions"""
|
||||||
|
|
||||||
self.__init__(
|
self.__init__(*args, **kwargs)
|
||||||
session=session,
|
|
||||||
name=name,
|
|
||||||
description=description,
|
|
||||||
image=image,
|
|
||||||
recipeYield=recipeYield,
|
|
||||||
recipeIngredient=recipeIngredient,
|
|
||||||
recipeInstructions=recipeInstructions,
|
|
||||||
totalTime=totalTime,
|
|
||||||
recipeCuisine=recipeCuisine,
|
|
||||||
prepTime=prepTime,
|
|
||||||
performTime=performTime,
|
|
||||||
nutrition=nutrition,
|
|
||||||
tools=tools,
|
|
||||||
slug=slug,
|
|
||||||
recipeCategory=recipeCategory,
|
|
||||||
tags=tags,
|
|
||||||
dateAdded=dateAdded,
|
|
||||||
notes=notes,
|
|
||||||
rating=rating,
|
|
||||||
orgURL=orgURL,
|
|
||||||
extras=extras,
|
|
||||||
)
|
|
||||||
|
|
|
@ -25,7 +25,9 @@ class RecipeStep(BaseModel):
|
||||||
class RecipeAsset(BaseModel):
|
class RecipeAsset(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
icon: str
|
icon: str
|
||||||
path: str
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
||||||
|
|
||||||
|
|
||||||
class Nutrition(BaseModel):
|
class Nutrition(BaseModel):
|
||||||
|
@ -76,6 +78,7 @@ class Recipe(RecipeSummary):
|
||||||
performTime: Optional[str] = None
|
performTime: Optional[str] = None
|
||||||
|
|
||||||
# Mealie Specific
|
# Mealie Specific
|
||||||
|
assets: Optional[list[RecipeAsset]] = []
|
||||||
dateAdded: Optional[datetime.date]
|
dateAdded: Optional[datetime.date]
|
||||||
notes: Optional[List[RecipeNote]] = []
|
notes: Optional[List[RecipeNote]] = []
|
||||||
orgURL: Optional[str]
|
orgURL: Optional[str]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue