mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-16 04:43:13 -05:00
feat: add support for API extras on shopping lists, shopping list items, and food data (#1619)
* added api extras to other tables genericized api extras model from recipes added extras column to ingredient foods added extras column to shopping lists added extras column to shopping list items * updated alembic version test * made mypy happy * added TODO on test that does nothing * added extras tests for lists, items, and foods * added docs for new extras * modified alembic versions to eliminate branching
This commit is contained in:
@@ -4,7 +4,9 @@ from datetime import datetime
|
||||
from typing import Optional, Union
|
||||
|
||||
from pydantic import UUID4
|
||||
from pydantic.utils import GetterDict
|
||||
|
||||
from mealie.db.models.group.shopping_list import ShoppingList, ShoppingListItem
|
||||
from mealie.schema._mealie import MealieModel
|
||||
from mealie.schema.recipe.recipe_ingredient import IngredientFood, IngredientUnit
|
||||
from mealie.schema.response.pagination import PaginationBase
|
||||
@@ -39,6 +41,7 @@ class ShoppingListItemCreate(MealieModel):
|
||||
|
||||
label_id: Optional[UUID4] = None
|
||||
recipe_references: list[ShoppingListItemRecipeRef] = []
|
||||
extras: Optional[dict] = {}
|
||||
|
||||
created_at: Optional[datetime]
|
||||
update_at: Optional[datetime]
|
||||
@@ -55,9 +58,17 @@ class ShoppingListItemOut(ShoppingListItemUpdate):
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
@classmethod
|
||||
def getter_dict(cls, name_orm: ShoppingListItem):
|
||||
return {
|
||||
**GetterDict(name_orm),
|
||||
"extras": {x.key_name: x.value for x in name_orm.extras},
|
||||
}
|
||||
|
||||
|
||||
class ShoppingListCreate(MealieModel):
|
||||
name: str = None
|
||||
extras: Optional[dict] = {}
|
||||
|
||||
created_at: Optional[datetime]
|
||||
update_at: Optional[datetime]
|
||||
@@ -84,6 +95,13 @@ class ShoppingListSummary(ShoppingListSave):
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
@classmethod
|
||||
def getter_dict(cls, name_orm: ShoppingList):
|
||||
return {
|
||||
**GetterDict(name_orm),
|
||||
"extras": {x.key_name: x.value for x in name_orm.extras},
|
||||
}
|
||||
|
||||
|
||||
class ShoppingListPagination(PaginationBase):
|
||||
items: list[ShoppingListSummary]
|
||||
|
||||
Reference in New Issue
Block a user