Skip to content

Commit

Permalink
166152327-story(Nutrition plan): Upgrade nutriron plan
Browse files Browse the repository at this point in the history
- Update nutrition plan to have data for consumed foods

[#166152327]
  • Loading branch information
Kimaiyo077 committed Jun 12, 2019
1 parent 040ee90 commit 0ae68a9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
6 changes: 6 additions & 0 deletions wger/nutrition/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ class MealItemForm(forms.ModelForm):
required=False)
ingredient = forms.ModelChoiceField(queryset=Ingredient.objects.all(),
widget=forms.HiddenInput)
MTYPES = (
('Planned', 'Planned'),
('Consumed', 'Consumed')
)

meal_type = forms.ChoiceField(label='Meal Type', widget=forms.Select, choices=MTYPES)

class Meta:
model = MealItem
Expand Down
18 changes: 18 additions & 0 deletions wger/nutrition/migrations/0003_mealitem_meal_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.2 on 2019-06-12 18:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nutrition', '0002_mealitem_time'),
]

operations = [
migrations.AddField(
model_name='mealitem',
name='meal_type',
field=models.CharField(default='Planned', max_length=15, verbose_name='Type'),
),
]
4 changes: 4 additions & 0 deletions wger/nutrition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,10 @@ class MealItem(models.Model):
time = Html5TimeField(null=True,
blank=True,
verbose_name=_('Time (approx)'))

meal_type = models.CharField(max_length=15,
verbose_name=_('Type'),
default=('Planned'))

def __str__(self):
'''
Expand Down
1 change: 1 addition & 0 deletions wger/nutrition/templates/meal_item/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
</div>
{% render_form_field form.amount %}
{% render_form_field form.weight_unit %}
{% render_form_field form.meal_type %}
{% render_form_submit submit_text %}
</form>
{% endblock %}
9 changes: 8 additions & 1 deletion wger/nutrition/templates/plan/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<tr style="background: #E0E0E0;">
<th>{% trans "Meal" %}</th>
<th>{% trans "Contents" %}</th>
<th>{% trans "Type" %}</th>
<th class="align-right">{% trans "Energy" %}</th>
<th class="align-right">{% trans "Protein" %}</th>
<th class="align-right">{% trans "Carbohydrates" %}</th>
Expand All @@ -57,7 +58,7 @@
</thead>
<tbody>
<tr>
<td colspan="2"></td>
<td colspan="3"></td>
<td class="align-right">{% trans 'kcal' %}</td>
<td class="align-right">{% trans_weight_unit 'g' owner_user %}</td>
<td class="align-right">{% trans_weight_unit 'g' owner_user %}</td>
Expand Down Expand Up @@ -110,6 +111,12 @@
</span>
{% endif %}
</td>
{% if item.meal_type == "Planned" %}
<td class="align-right">{% trans "Planned" %}</td>

{% elif item.meal_type == "Consumed" %}
<td class="align-right">{% trans "Consumed" %}</td>
{% endif %}
<td class="align-right">{{item.get_nutritional_values.energy|floatformat}}</td>
<td class="align-right">{{item.get_nutritional_values.protein|floatformat}}</td>
<td class="align-right">{{item.get_nutritional_values.carbohydrates|floatformat}}</td>
Expand Down

0 comments on commit 0ae68a9

Please sign in to comment.