basic shopping list fix
This commit is contained in:
parent
78275145f8
commit
4ddc39f1c2
@ -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)
|
||||
|
@ -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 }} {% 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 }} {% endfor %}</textarea>
|
||||
<!--// @formatter:on-->
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user