From 863f9c6ce160960680eb4f51937933509dcd66a1 Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Sun, 23 Feb 2020 13:16:25 +0100 Subject: [PATCH] Added calories to profile and converted nutritional data to decimal fields --- .../migrations/0005_auto_20200223_1317.py | 73 +++++++++++++++++++ food_planner/models.py | 66 +++++++++++------ 2 files changed, 115 insertions(+), 24 deletions(-) create mode 100644 food_planner/migrations/0005_auto_20200223_1317.py diff --git a/food_planner/migrations/0005_auto_20200223_1317.py b/food_planner/migrations/0005_auto_20200223_1317.py new file mode 100644 index 0000000..2db2f01 --- /dev/null +++ b/food_planner/migrations/0005_auto_20200223_1317.py @@ -0,0 +1,73 @@ +# Generated by Django 3.0.3 on 2020-02-23 12:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('food_planner', '0004_recipe_calories'), + ] + + operations = [ + migrations.AddField( + model_name='profile', + name='daily_calories_demand', + field=models.DecimalField(decimal_places=2, default=2000.0, help_text='At most this amount of kilo calories is needed per day', max_digits=6, verbose_name='Daily kilo calories demand'), + ), + migrations.AlterField( + model_name='profile', + name='daily_carbohydrate_demand', + field=models.DecimalField(decimal_places=2, default=150.0, help_text='At most this amount of carbohydrates is needed per day', max_digits=5, verbose_name='Daily carbohydrate demand'), + ), + migrations.AlterField( + model_name='profile', + name='daily_fat_demand', + field=models.DecimalField(decimal_places=2, default=117.0, help_text='At most this amount of fat is needed per day', max_digits=5, verbose_name='Daily fat demand'), + ), + migrations.AlterField( + model_name='profile', + name='daily_protein_demand', + field=models.DecimalField(decimal_places=2, default=90.0, help_text='At most this amount of protein should be eaten per day', max_digits=5, verbose_name='Daily protein demand'), + ), + migrations.AlterField( + model_name='profile', + name='daily_roughage_demand', + field=models.DecimalField(decimal_places=2, default=30.0, help_text='At least this amount of roughage should be eaten per day', max_digits=5, verbose_name='Daily roughage demand'), + ), + migrations.AlterField( + model_name='profile', + name='daily_sugar_demand', + field=models.DecimalField(decimal_places=2, default=25.0, help_text='At most this amount of sugar is needed per day', max_digits=5, verbose_name='Daily sugar demand'), + ), + migrations.AlterField( + model_name='recipe', + name='calories', + field=models.DecimalField(decimal_places=2, help_text='How many kilo calories are contained in one portion?', max_digits=6, verbose_name='Kilo Calories'), + ), + migrations.AlterField( + model_name='recipe', + name='carbohydrates', + field=models.DecimalField(decimal_places=2, help_text='How much carbohydrates does one portion contain?', max_digits=5, verbose_name='Carbohydrates'), + ), + migrations.AlterField( + model_name='recipe', + name='fat', + field=models.DecimalField(decimal_places=2, help_text='How much fat does one portion contain?', max_digits=5, verbose_name='Fat'), + ), + migrations.AlterField( + model_name='recipe', + name='protein', + field=models.DecimalField(decimal_places=2, help_text='How much protein does one portion contain?', max_digits=5, verbose_name='Protein'), + ), + migrations.AlterField( + model_name='recipe', + name='roughage', + field=models.DecimalField(decimal_places=2, help_text='How much roughage does one portion contain?', max_digits=5, verbose_name='Roughage'), + ), + migrations.AlterField( + model_name='recipe', + name='sugar', + field=models.DecimalField(decimal_places=2, help_text='How much sugar does one portion contain?', max_digits=5, verbose_name='Sugar'), + ), + ] diff --git a/food_planner/models.py b/food_planner/models.py index af16f50..f436690 100644 --- a/food_planner/models.py +++ b/food_planner/models.py @@ -17,24 +17,42 @@ MEASUREMENT_UNITS = [('KG', 'kg'), class Profile(models.Model): user = models.OneToOneField(User, models.CASCADE) - daily_fat_demand = models.PositiveIntegerField(_('Daily fat demand'), - help_text=_('At most this amount of fat is needed per day'), - default=117) - daily_carbohydrate_demand = models.PositiveIntegerField( + daily_calories_demand = models.DecimalField(_('Daily kilo calories demand'), + help_text=_('At most this amount of kilo calories is needed per day'), + default=2000.00, + decimal_places=2, + max_digits=6) + daily_fat_demand = models.DecimalField(_('Daily fat demand'), + help_text=_('At most this amount of fat is needed per day'), + default=117.00, + decimal_places=2, + max_digits=5) + daily_carbohydrate_demand = models.DecimalField( _('Daily carbohydrate demand'), help_text=_('At most this amount of carbohydrates is needed per day'), - default=150) - daily_sugar_demand = models.PositiveIntegerField(_('Daily sugar demand'), - help_text=_('At most this amount of sugar is needed per day'), - default=25) - daily_roughage_demand = models.PositiveIntegerField( + default=150.00, + decimal_places=2, + max_digits=5, + ) + daily_sugar_demand = models.DecimalField(_('Daily sugar demand'), + help_text=_('At most this amount of sugar is needed per day'), + default=25.00, + decimal_places=2, + max_digits=5) + daily_roughage_demand = models.DecimalField( _('Daily roughage demand'), help_text=_('At least this amount of roughage should be eaten per day'), - default=30) - daily_protein_demand = models.PositiveIntegerField( + default=30.00, + decimal_places=2, + max_digits=5 + ) + daily_protein_demand = models.DecimalField( _('Daily protein demand'), help_text=_('At most this amount of protein should be eaten per day'), - default=90) + default=90.00, + decimal_places=2, + max_digits=5, + ) class Meta: verbose_name = _('Profile') @@ -82,18 +100,18 @@ class Recipe(models.Model): ('EXP', _('Expert')) ]) - calories = models.PositiveIntegerField(_('Calories'), - help_text=_('How many calories are contained in one portion?')) - fat = models.PositiveIntegerField(_('Fat'), - help_text=_('How much fat does one portion contain?')) - carbohydrates = models.PositiveIntegerField(_('Carbohydrates'), - help_text=_('How much carbohydrates does one portion contain?')) - sugar = models.PositiveIntegerField(_('Sugar'), - help_text=_('How much sugar does one portion contain?')) - roughage = models.PositiveIntegerField(_('Roughage'), - help_text=_('How much roughage does one portion contain?')) - protein = models.PositiveIntegerField(_('Protein'), - help_text=_('How much protein does one portion contain?')) + calories = models.DecimalField(_('Kilo Calories'), decimal_places=2, max_digits=6, + help_text=_('How many kilo calories are contained in one portion?')) + fat = models.DecimalField(_('Fat'), decimal_places=2, max_digits=5, + help_text=_('How much fat does one portion contain?')) + carbohydrates = models.DecimalField(_('Carbohydrates'), decimal_places=2, max_digits=5, + help_text=_('How much carbohydrates does one portion contain?')) + sugar = models.DecimalField(_('Sugar'), decimal_places=2, max_digits=5, + help_text=_('How much sugar does one portion contain?')) + roughage = models.DecimalField(_('Roughage'), decimal_places=2, max_digits=5, + help_text=_('How much roughage does one portion contain?')) + protein = models.DecimalField(_('Protein'), decimal_places=2, max_digits=5, + help_text=_('How much protein does one portion contain?')) class Meta: verbose_name = _('Recipe')