Refactor food item nutrition field names for consistency

Standardized field names for nutritional values in FoodItem model and throughout the codebase, changing 'fats_100g' to 'fat_100', 'saturated_fats_100g' to 'saturated_fat_100', and similar updates for other fields. Updated all references in models, templates, routes, and seed data to match the new naming convention for improved clarity and consistency.
This commit is contained in:
2025-06-29 16:36:05 +02:00
parent 0ec930f86d
commit e00bfee948
7 changed files with 62 additions and 62 deletions

View File

@@ -13,8 +13,8 @@ Food Nutritional Info
<tr>
<th>Name</th>
<th>Energy (kcal)</th>
<th>Fats (g)</th>
<th>Saturated Fats (g)</th>
<th>fat (g)</th>
<th>Saturated fat (g)</th>
<th>Sugars (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
@@ -25,12 +25,12 @@ Food Nutritional Info
{% for food in items %}
<tr>
<td class="bg-body-tertiary">{{ food.name }}</td>
<td class="bg-body-tertiary">{{ food.energy_100g }}</td>
<td class="bg-body-tertiary">{{ food.fats_100g }}</td>
<td class="bg-body-tertiary">{{ food.saturated_fats_100g }}</td>
<td class="bg-body-tertiary">{{ food.sugar_100g }}</td>
<td class="bg-body-tertiary">{{ food.carbs_100g }}</td>
<td class="bg-body-tertiary">{{ food.protein_100g }}</td>
<td class="bg-body-tertiary">{{ food.energy_100 }}</td>
<td class="bg-body-tertiary">{{ food.fat_100 }}</td>
<td class="bg-body-tertiary">{{ food.saturated_fat_100 }}</td>
<td class="bg-body-tertiary">{{ food.sugar_100 }}</td>
<td class="bg-body-tertiary">{{ food.carbs_100 }}</td>
<td class="bg-body-tertiary">{{ food.protein_100 }}</td>
<td class="bg-body-tertiary">
<form method="POST" action="{{ url_for('admin.delete_food', id=food.id) }}"
onsubmit="return confirm('Are you sure you want to delete this item?');">

View File

@@ -9,30 +9,30 @@
<div class="card-body">
<dl class="row">
<dt class="col-sm-5">Energy per 100g</dt>
<dd class="col-sm-7">{{ item.energy_100g }} kcal</dd>
<dd class="col-sm-7">{{ item.energy_100 }} kcal</dd>
<dt class="col-sm-5">Protein per 100g</dt>
<dd class="col-sm-7">{{ "%.1f"|format(item.protein_100g) }} g</dd>
<dd class="col-sm-7">{{ "%.1f"|format(item.protein_100) }} g</dd>
<dt class="col-sm-5">Carbohydrates per 100g</dt>
<dd class="col-sm-7">{{ "%.1f"|format(item.carbs_100g) }} g</dd>
<dd class="col-sm-7">{{ "%.1f"|format(item.carbs_100) }} g</dd>
<dt class="col-sm-5">Sugar per 100g</dt>
<dd class="col-sm-7">
{% if item.sugar_100g is not none %}
{{ "%.1f"|format(item.sugar_100g) }} g
{% if item.sugar_100 is not none %}
{{ "%.1f"|format(item.sugar_100) }} g
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</dd>
<dt class="col-sm-5">Fats per 100g</dt>
<dd class="col-sm-7">{{ "%.1f"|format(item.fats_100g) }} g</dd>
<dt class="col-sm-5">fat per 100g</dt>
<dd class="col-sm-7">{{ "%.1f"|format(item.fat_100) }} g</dd>
<dt class="col-sm-5">Saturated fats per 100g</dt>
<dt class="col-sm-5">Saturated fat per 100g</dt>
<dd class="col-sm-7">
{% if item.saturated_fats_100g is not none %}
{{ "%.1f"|format(item.saturated_fats_100g) }} g
{% if item.saturated_fat_100 is not none %}
{{ "%.1f"|format(item.saturated_fat_100) }} g
{% else %}
<span class="text-muted">N/A</span>
{% endif %}

View File

@@ -56,12 +56,12 @@ def edit_food_item(barcode: int):
return redirect(url_for("user.dashboard"))
form.barcode.data = item.barcode
form.name.data = item.name
form.energy.data = item.energy_100g
form.protein.data = item.protein_100g
form.carbs.data = item.carbs_100g
form.sugar.data = item.sugar_100g
form.fat.data = item.fats_100g
form.saturated_fat.data = item.saturated_fats_100g
form.energy.data = item.energy_100
form.protein.data = item.protein_100
form.carbs.data = item.carbs_100
form.sugar.data = item.sugar_100
form.fat.data = item.fat_100
form.saturated_fat.data = item.saturated_fat_100
return render_template("edit_food_item.html", form=form)
else:
return redirect(url_for("user.dashboard"))

View File

@@ -13,8 +13,8 @@ Food Nutritional Info
<tr>
<th>Name</th>
<th>Energy (kcal)</th>
<th>Fats (g)</th>
<th>Saturated Fats (g)</th>
<th>fat (g)</th>
<th>Saturated fat (g)</th>
<th>Sugars (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
@@ -25,12 +25,12 @@ Food Nutritional Info
{% for food in items %}
<tr>
<td class="bg-body-tertiary">{{ food.name }}</td>
<td class="bg-body-tertiary">{{ food.energy_100g }}</td>
<td class="bg-body-tertiary">{{ food.fats_100g }}</td>
<td class="bg-body-tertiary">{{ food.saturated_fats_100g }}</td>
<td class="bg-body-tertiary">{{ food.sugar_100g }}</td>
<td class="bg-body-tertiary">{{ food.carbs_100g }}</td>
<td class="bg-body-tertiary">{{ food.protein_100g }}</td>
<td class="bg-body-tertiary">{{ food.energy_100 }}</td>
<td class="bg-body-tertiary">{{ food.fat_100 }}</td>
<td class="bg-body-tertiary">{{ food.saturated_fat_100 }}</td>
<td class="bg-body-tertiary">{{ food.sugar_100 }}</td>
<td class="bg-body-tertiary">{{ food.carbs_100 }}</td>
<td class="bg-body-tertiary">{{ food.protein_100 }}</td>
<td class="bg-body-tertiary">
<div class="d-flex gap-1">
<form method="GET" action="{{ url_for('user.edit_food_item', barcode=food.barcode) }}">