added auto shopping functionality. fixed bug when there are no matching recipes

This commit is contained in:
AquaticLava
2023-08-01 21:52:59 -06:00
parent df684f591a
commit ecd828008e
4 changed files with 43 additions and 6 deletions

View File

@ -688,6 +688,8 @@ class AutoPlanViewSet(viewsets.ViewSet):
for keyword in keywords:
recipes = recipes.filter(keywords__name=keyword['name'])
if len(recipes) == 0:
return Response(serializer.data)
recipes = recipes.order_by('?')[:days]
recipes = list(recipes)
@ -707,7 +709,7 @@ class AutoPlanViewSet(viewsets.ViewSet):
for m in meal_plans:
m.shared.set(shared_pks)
if request.data.get('addshopping', False) and request.data.get('recipe', None):
if request.data.get('addshopping', False):
SLR = RecipeShoppingEditor(user=request.user, space=request.space)
SLR.create(mealplan=m, servings=servings)