basic shopping list fix

This commit is contained in:
vabene1111 2020-06-29 18:11:25 +02:00
parent 78275145f8
commit 4ddc39f1c2
3 changed files with 14 additions and 10 deletions

View File

@ -189,6 +189,9 @@ class Recipe(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
class Comment(models.Model):
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)

View File

@ -26,7 +26,7 @@
<div class="row">
<div class="col col-md-12">
<!--// @formatter:off-->
<textarea id="id_list" class="form-control" rows="{{ ingredients|length|add:1 }}">{% for i in ingredients %}{% if markdown_format %}- [ ] {% endif %}{{ i.amount.normalize }} {{ i.unit }} {{ i.ingredient.name }}&#13;&#10;{% endfor %}</textarea>
<textarea id="id_list" class="form-control" rows="{{ ingredients|length|add:1 }}">{% for i in ingredients %}{% if markdown_format %}- [ ] {% endif %}{{ i.amount.normalize }} {{ i.unit }} {{ i.food.name }}&#13;&#10;{% endfor %}</textarea>
<!--// @formatter:on-->
</div>
</div>

View File

@ -189,16 +189,17 @@ def shopping_list(request):
ingredients = []
for r in recipes:
for ri in RecipeIngredient.objects.filter(recipe=r).exclude(unit__name__contains='Special:').all():
index = None
for x, ig in enumerate(ingredients):
if ri.ingredient == ig.ingredient and ri.unit == ig.unit:
index = x
for s in r.steps.all():
for ri in s.ingredients.exclude(unit__name__contains='Special:').all():
index = None
for x, ig in enumerate(ingredients):
if ri.food == ig.food and ri.unit == ig.unit:
index = x
if index:
ingredients[index].amount = ingredients[index].amount + ri.amount
else:
ingredients.append(ri)
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, 'markdown_format': markdown_format})