fixed ingredient amount numeric
This commit is contained in:
parent
f1c5a0ef5f
commit
bdd092e5d3
@ -26,6 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% if field.name == 'name' %}
|
{% if field.name == 'name' %}
|
||||||
<label>{% trans 'Ingredients' %}</label>
|
<label>{% trans 'Ingredients' %}</label>
|
||||||
|
{{ form.ingredients.errors }}
|
||||||
<div id="ingredients-table"></div>
|
<div id="ingredients-table"></div>
|
||||||
<br>
|
<br>
|
||||||
<div class="table-controls" style="text-align: center">
|
<div class="table-controls" style="text-align: center">
|
||||||
@ -144,7 +145,7 @@
|
|||||||
validator: "required",
|
validator: "required",
|
||||||
editor: select2IngredientEditor
|
editor: select2IngredientEditor
|
||||||
},
|
},
|
||||||
{title: "{% trans 'Amount' %}", field: "amount", validator: "required", editor: "input"},
|
{title: "{% trans 'Amount' %}", field: "amount", validator: "required", editor: "number"},
|
||||||
{
|
{
|
||||||
title: "{% trans 'Unit' %}",
|
title: "{% trans 'Unit' %}",
|
||||||
field: "unit__name",
|
field: "unit__name",
|
||||||
|
@ -98,7 +98,10 @@ def internal_recipe_update(request, pk):
|
|||||||
recipe_ingredient.ingredient = ingredient
|
recipe_ingredient.ingredient = ingredient
|
||||||
|
|
||||||
if isinstance(i['amount'], str):
|
if isinstance(i['amount'], str):
|
||||||
recipe_ingredient.amount = float(i['amount'].replace(',', '.'))
|
try:
|
||||||
|
recipe_ingredient.amount = float(i['amount'].replace(',', '.'))
|
||||||
|
except ValueError:
|
||||||
|
form.add_error("ingredients", _('There was an error converting your ingredients amount to a number: ') + i['unit__name'])
|
||||||
else:
|
else:
|
||||||
recipe_ingredient.amount = i['amount']
|
recipe_ingredient.amount = i['amount']
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user