feat: Add Household Filter to Meal Plan Rules (#4231)

This commit is contained in:
Michael Genson
2024-09-27 09:06:45 -05:00
committed by GitHub
parent 38502e82d4
commit 4712994242
13 changed files with 533 additions and 87 deletions

View File

@@ -9,14 +9,16 @@ from .new_meal import (
UpdatePlanEntry,
)
from .plan_rules import (
Category,
BasePlanRuleFilter,
PlanCategory,
PlanHousehold,
PlanRulesCreate,
PlanRulesDay,
PlanRulesOut,
PlanRulesPagination,
PlanRulesSave,
PlanRulesType,
Tag,
PlanTag,
)
from .shopping_list import ListItem, ShoppingListIn, ShoppingListOut
@@ -31,12 +33,14 @@ __all__ = [
"ReadPlanEntry",
"SavePlanEntry",
"UpdatePlanEntry",
"Category",
"BasePlanRuleFilter",
"PlanCategory",
"PlanHousehold",
"PlanRulesCreate",
"PlanRulesDay",
"PlanRulesOut",
"PlanRulesPagination",
"PlanRulesSave",
"PlanRulesType",
"Tag",
"PlanTag",
]

View File

@@ -5,19 +5,27 @@ from pydantic import UUID4, ConfigDict
from sqlalchemy.orm import joinedload
from sqlalchemy.orm.interfaces import LoaderOption
from mealie.db.models.household import GroupMealPlanRules
from mealie.db.models.household import GroupMealPlanRules, Household
from mealie.db.models.recipe import Category, Tag
from mealie.schema._mealie import MealieModel
from mealie.schema.response.pagination import PaginationBase
class Category(MealieModel):
class BasePlanRuleFilter(MealieModel):
id: UUID4
name: str
slug: str
class PlanCategory(BasePlanRuleFilter):
model_config = ConfigDict(from_attributes=True)
class Tag(Category):
class PlanTag(BasePlanRuleFilter):
model_config = ConfigDict(from_attributes=True)
class PlanHousehold(BasePlanRuleFilter):
model_config = ConfigDict(from_attributes=True)
@@ -51,8 +59,9 @@ class PlanRulesType(str, Enum):
class PlanRulesCreate(MealieModel):
day: PlanRulesDay = PlanRulesDay.unset
entry_type: PlanRulesType = PlanRulesType.unset
categories: list[Category] = []
tags: list[Tag] = []
categories: list[PlanCategory] = []
tags: list[PlanTag] = []
households: list[PlanHousehold] = []
class PlanRulesSave(PlanRulesCreate):
@@ -66,7 +75,23 @@ class PlanRulesOut(PlanRulesSave):
@classmethod
def loader_options(cls) -> list[LoaderOption]:
return [joinedload(GroupMealPlanRules.categories), joinedload(GroupMealPlanRules.tags)]
return [
joinedload(GroupMealPlanRules.categories).load_only(
Category.id,
Category.name,
Category.slug,
),
joinedload(GroupMealPlanRules.tags).load_only(
Tag.id,
Tag.name,
Tag.slug,
),
joinedload(GroupMealPlanRules.households).load_only(
Household.id,
Household.name,
Household.slug,
),
]
class PlanRulesPagination(PaginationBase):