group ingredients in shopping list
This commit is contained in:
@ -137,8 +137,16 @@ def shopping_list(request):
|
|||||||
ingredients = []
|
ingredients = []
|
||||||
|
|
||||||
for r in recipes:
|
for r in recipes:
|
||||||
for i in RecipeIngredient.objects.filter(recipe=r).all():
|
for ri in RecipeIngredient.objects.filter(recipe=r).all():
|
||||||
ingredients.append(i)
|
index = None
|
||||||
|
for x, ig in enumerate(ingredients):
|
||||||
|
if ri.ingredient == ig.ingredient and ri.unit == ig.unit:
|
||||||
|
index = x
|
||||||
|
|
||||||
|
if index:
|
||||||
|
ingredients[index].amount = ingredients[index].amount + ri.amount
|
||||||
|
else:
|
||||||
|
ingredients.append(ri)
|
||||||
|
|
||||||
return render(request, 'shopping_list.html', {'ingredients': ingredients, 'recipes': recipes, 'form': form})
|
return render(request, 'shopping_list.html', {'ingredients': ingredients, 'recipes': recipes, 'form': form})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user