mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
add recipeSettings model
This commit is contained in:
parent
4f2b6ebdb4
commit
eb74386f49
4 changed files with 41 additions and 9 deletions
|
@ -11,6 +11,7 @@ from mealie.db.models.recipe.ingredient import RecipeIngredient
|
|||
from mealie.db.models.recipe.instruction import RecipeInstruction
|
||||
from mealie.db.models.recipe.note import Note
|
||||
from mealie.db.models.recipe.nutrition import Nutrition
|
||||
from mealie.db.models.recipe.settings import RecipeSettings
|
||||
from mealie.db.models.recipe.tag import Tag, recipes2tags
|
||||
from mealie.db.models.recipe.tool import Tool
|
||||
from sqlalchemy.ext.orderinglist import ordering_list
|
||||
|
@ -52,6 +53,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
|||
|
||||
# Mealie Specific
|
||||
slug = sa.Column(sa.String, index=True, unique=True)
|
||||
settings = orm.relationship("RecipeSettings", uselist=False, cascade="all, delete-orphan")
|
||||
tags: list[Tag] = orm.relationship("Tag", secondary=recipes2tags, back_populates="recipes")
|
||||
dateAdded = sa.Column(sa.Date, default=date.today)
|
||||
notes: list[Note] = orm.relationship("Note", cascade="all, delete-orphan")
|
||||
|
@ -88,6 +90,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
|||
orgURL: str = None,
|
||||
extras: dict = None,
|
||||
assets: list = None,
|
||||
settings: dict = None,
|
||||
*args,
|
||||
**kwargs
|
||||
) -> None:
|
||||
|
@ -97,6 +100,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
|||
self.recipeCuisine = recipeCuisine
|
||||
|
||||
self.nutrition = Nutrition(**nutrition) if self.nutrition else Nutrition()
|
||||
|
||||
self.tools = [Tool(tool=x) for x in tools] if tools else []
|
||||
|
||||
self.recipeYield = recipeYield
|
||||
|
@ -113,6 +117,8 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
|||
self.recipeCategory = [Category.create_if_not_exist(session=session, name=cat) for cat in recipeCategory]
|
||||
|
||||
# Mealie Specific
|
||||
self.settings = RecipeSettings(**settings) if settings else RecipeSettings()
|
||||
print(self.settings)
|
||||
self.tags = [Tag.create_if_not_exist(session=session, name=tag) for tag in tags]
|
||||
self.slug = slug
|
||||
self.dateAdded = dateAdded
|
||||
|
@ -123,5 +129,4 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
|||
|
||||
def update(self, *args, **kwargs):
|
||||
"""Updated a database entry by removing nested rows and rebuilds the row through the __init__ functions"""
|
||||
|
||||
self.__init__(*args, **kwargs)
|
||||
|
|
18
mealie/db/models/recipe/settings.py
Normal file
18
mealie/db/models/recipe/settings.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import sqlalchemy as sa
|
||||
from mealie.db.models.model_base import SqlAlchemyBase
|
||||
|
||||
|
||||
class RecipeSettings(SqlAlchemyBase):
|
||||
__tablename__ = "recipe_settings"
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
parent_id = sa.Column(sa.Integer, sa.ForeignKey("recipes.id"))
|
||||
public = sa.Column(sa.Boolean)
|
||||
show_nutrition = sa.Column(sa.Boolean)
|
||||
show_assets = sa.Column(sa.Boolean)
|
||||
landscape_view = sa.Column(sa.Boolean)
|
||||
|
||||
def __init__(self, public=True, show_nutrition=True, show_assets=True, landscape_view=True) -> None:
|
||||
self.public = public
|
||||
self.show_nutrition = show_nutrition
|
||||
self.show_assets = show_assets
|
||||
self.landscape_view = landscape_view
|
|
@ -2,7 +2,6 @@ import shutil
|
|||
|
||||
from fastapi import APIRouter, Depends, File, Form
|
||||
from fastapi.datastructures import UploadFile
|
||||
from fastapi.routing import run_endpoint_function
|
||||
from mealie.core.config import app_dirs
|
||||
from mealie.db.database import db
|
||||
from mealie.db.db_setup import generate_session
|
||||
|
@ -20,7 +19,6 @@ router = APIRouter(prefix="/api/recipes", tags=["Recipe Assets"])
|
|||
async def get_recipe_asset(recipe_slug, file_name: str):
|
||||
""" Returns a recipe asset """
|
||||
file = app_dirs.RECIPE_DATA_DIR.joinpath(recipe_slug, file_name)
|
||||
|
||||
return FileResponse(file)
|
||||
|
||||
|
||||
|
|
|
@ -1,13 +1,23 @@
|
|||
import datetime
|
||||
from typing import Any, List, Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
from fastapi_camelcase import CamelModel
|
||||
from mealie.db.models.recipe.recipe import RecipeModel
|
||||
from pydantic import BaseModel, validator
|
||||
from pydantic import BaseModel, Field, validator
|
||||
from pydantic.utils import GetterDict
|
||||
from slugify import slugify
|
||||
|
||||
|
||||
class RecipeSettings(CamelModel):
|
||||
public: bool = True
|
||||
show_nutrition: bool = True
|
||||
show_assets: bool = True
|
||||
landscape_view: bool = True
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class RecipeNote(BaseModel):
|
||||
title: str
|
||||
text: str
|
||||
|
@ -53,8 +63,8 @@ class RecipeSummary(BaseModel):
|
|||
image: Optional[Any]
|
||||
|
||||
description: Optional[str]
|
||||
recipeCategory: Optional[List[str]] = []
|
||||
tags: Optional[List[str]] = []
|
||||
recipeCategory: Optional[list[str]] = []
|
||||
tags: Optional[list[str]] = []
|
||||
rating: Optional[int]
|
||||
|
||||
class Config:
|
||||
|
@ -81,9 +91,10 @@ class Recipe(RecipeSummary):
|
|||
performTime: Optional[str] = None
|
||||
|
||||
# Mealie Specific
|
||||
settings: Optional[RecipeSettings]
|
||||
assets: Optional[list[RecipeAsset]] = []
|
||||
dateAdded: Optional[datetime.date]
|
||||
notes: Optional[List[RecipeNote]] = []
|
||||
notes: Optional[list[RecipeNote]] = []
|
||||
orgURL: Optional[str]
|
||||
extras: Optional[dict] = {}
|
||||
|
||||
|
@ -139,7 +150,7 @@ class Recipe(RecipeSummary):
|
|||
|
||||
|
||||
class AllRecipeRequest(BaseModel):
|
||||
properties: List[str]
|
||||
properties: list[str]
|
||||
limit: Optional[int]
|
||||
|
||||
class Config:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue