Self hosted FLOSS fitness/workout, nutrition and weight tracker
Set additional properties to model ingredient
Roland Geider2b0c6737b628
diff --git a/nutrition/models.py b/nutrition/models.pyindex ed9dd82e6..d121d5509 100644--- a/nutrition/models.py+++ b/nutrition/models.py@@ -65,7 +65,12 @@ class NutritionPlan(models.Model):nutritional_info['energy'] += item.ingredient.energy * item.amount_gramm / 100nutritional_info['protein'] += item.ingredient.protein * item.amount_gramm / 100nutritional_info['carbohydrates'] += item.ingredient.carbohydrates * item.amount_gramm / 100+ if item.ingredient.carbohydrates_sugar:+ nutritional_info['carbohydrates_sugar'] += item.ingredient.carbohydrates_sugar * item.amount_gramm / 100+nutritional_info['fat'] += item.ingredient.fat * item.amount_gramm / 100+ if item.ingredient.fat_saturated:+ nutritional_info['fat_saturated'] += item.ingredient.fat_saturated * item.amount_gramm / 100if item.ingredient.fibres:nutritional_info['fibres'] += item.ingredient.fibres * item.amount_gramm / 100@@ -99,17 +104,19 @@ class Ingredient(models.Model):verbose_name = _('Carbohydrates'),help_text = _('In g per 100g of product'))- carbohydrates_sugar = models.FloatField(- verbose_name = _('Sugar content in carbohydrates'),- help_text = _('In g per 100g of product'))+ carbohydrates_sugar = models.FloatField(blank = True,+ null = True,+ verbose_name = _('Sugar content in carbohydrates'),+ help_text = _('In g per 100g of product'))fat = models.FloatField(blank = True,verbose_name = _('Fat'),help_text = _('In g per 100g of product'))- fat_saturated = models.FloatField(- verbose_name = _('Saturated fat content in fats'),- help_text = _('In g per 100g of product'))+ fat_saturated = models.FloatField(blank = True,+ null = True,+ verbose_name = _('Saturated fat content in fats'),+ help_text = _('In g per 100g of product'))fibres = models.FloatField(blank = True,null = True,@@ -117,9 +124,9 @@ class Ingredient(models.Model):help_text = _('In g per 100g of product'))sodium = models.FloatField(blank = True,- null = True,- verbose_name = _('Sodium'),- help_text = _('In g per 100g of product'))+ null = True,+ verbose_name = _('Sodium'),+ help_text = _('In g per 100g of product'))def __unicode__(self):"""Return a more human-readable representationdiff --git a/nutrition/templates/edit_ingredient.html b/nutrition/templates/edit_ingredient.htmlindex 383d93b1b..e6b450de8 100644--- a/nutrition/templates/edit_ingredient.html+++ b/nutrition/templates/edit_ingredient.html@@ -23,7 +23,7 @@{% include "form_snippet.html" with field=form.fat %}{% include "form_snippet.html" with field=form.fat_saturated %}{% include "form_snippet.html" with field=form.fibres %}- {% include "form_snippet.html" with field=form.natrium %}+ {% include "form_snippet.html" with field=form.sodium %}<tr><td><input type="submit" value="{% trans "Save" %}" /></td><td></td>diff --git a/nutrition/templates/view_ingredient.html b/nutrition/templates/view_ingredient.htmlindex eb96fa4cf..01c299e85 100644--- a/nutrition/templates/view_ingredient.html+++ b/nutrition/templates/view_ingredient.html@@ -22,6 +22,7 @@ $(document).ready(function() {<h2>{{ingredient.name}}</h2>+<p>{% trans "Nutritional values in 100g of product." %}</p><table><thead>@@ -73,8 +74,8 @@ $(document).ready(function() {<td>{% if ingredient.fibres %}{{ingredient.fibres}} g{% else %}-/-{% endif %}</td></tr><tr>- <td>{% trans "Natrium" %}</td>- <td>{% if ingredient.natrium %}{{ingredient.natrium}} g{% else %}-/-{% endif %}</td>+ <td>{% trans "Sodium" %}</td>+ <td>{% if ingredient.sodium %}{{ingredient.sodium}} g{% else %}-/-{% endif %}</td></tr></tbody></table>