Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add first draft for model for nutrition diary
Roland Geidere9fefead4e79
diff --git a/wger/nutrition/migrations/0002_auto_20160510_1140.py b/wger/nutrition/migrations/0002_auto_20160510_1140.pynew file mode 100644index 000000000..736ed2e09--- /dev/null+++ b/wger/nutrition/migrations/0002_auto_20160510_1140.py@@ -0,0 +1,39 @@+# -*- coding: utf-8 -*-+from __future__ import unicode_literals++from django.db import migrations, models+import wger.nutrition.models+import django.core.validators+++class Migration(migrations.Migration):++ dependencies = [+ ('nutrition', '0001_initial'),+ ]++ operations = [+ migrations.CreateModel(+ name='LogItem',+ fields=[+ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),+ ('datetime', models.DateTimeField(auto_now=True)),+ ('comment', models.TextField(verbose_name='Comment', blank=True)),+ ('amount', models.DecimalField(verbose_name='Amount', max_digits=6, decimal_places=2, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(1000)])),+ ('ingredient', models.ForeignKey(verbose_name='Ingredient', to='nutrition.Ingredient')),+ ('plan', models.ForeignKey(editable=False, to='nutrition.NutritionPlan', verbose_name='Nutrition plan')),+ ('weight_unit', models.ForeignKey(verbose_name='Weight unit', blank=True, to='nutrition.IngredientWeightUnit', null=True)),+ ],+ bases=(wger.nutrition.models.BaseMealItem, models.Model),+ ),+ migrations.AlterField(+ model_name='meal',+ name='order',+ field=models.IntegerField(verbose_name='Order', editable=False, blank=True),+ ),+ migrations.AlterField(+ model_name='mealitem',+ name='order',+ field=models.IntegerField(verbose_name='Order', editable=False, blank=True),+ ),+ ]diff --git a/wger/nutrition/models.py b/wger/nutrition/models.pyindex 21d56c47a..287cc1596 100644--- a/wger/nutrition/models.py+++ b/wger/nutrition/models.py@@ -565,42 +565,12 @@ class Meal(models.Model):return nutritional_info-@python_2_unicode_compatible-class MealItem(models.Model):- '''- An item (component) of a meal+class BaseMealItem(object):'''+ Base class for an item (component) of a meal or log- meal = models.ForeignKey(Meal,- verbose_name=_('Nutrition plan'),- editable=False)- ingredient = models.ForeignKey(Ingredient, verbose_name=_('Ingredient'))- weight_unit = models.ForeignKey(IngredientWeightUnit,- verbose_name=_('Weight unit'),- null=True,- blank=True,- )-- order = models.IntegerField(verbose_name=_('Order'),- blank=True,- editable=False)- amount = models.DecimalField(decimal_places=2,- max_digits=6,- verbose_name=_('Amount'),- validators=[MinValueValidator(1),- MaxValueValidator(1000)])-- def __str__(self):- '''- Return a more human-readable representation- '''- return u"{0}g ingredient {1}".format(self.amount, self.ingredient_id)-- def get_owner_object(self):- '''- Returns the object that has owner information- '''- return self.meal.plan+ This just provides some common helper functions+ '''def get_unit_type(self):'''@@ -671,3 +641,113 @@ class MealItem(models.Model):nutritional_info[i] = Decimal(nutritional_info[i]).quantize(TWOPLACES)return nutritional_info+++@python_2_unicode_compatible+class MealItem(BaseMealItem, models.Model):+ '''+ An item (component) of a meal+ '''+ meal = models.ForeignKey(Meal,+ verbose_name=_('Nutrition plan'),+ editable=False)+ ingredient = models.ForeignKey(Ingredient, verbose_name=_('Ingredient'))+ '''+ Ingredient+ '''++ weight_unit = models.ForeignKey(IngredientWeightUnit,+ verbose_name=_('Weight unit'),+ null=True,+ blank=True,+ )+ '''+ Weight unit used (grams, slices, etc.)+ '''++ amount = models.DecimalField(decimal_places=2,+ max_digits=6,+ verbose_name=_('Amount'),+ validators=[MinValueValidator(1),+ MaxValueValidator(1000)])+ '''+ The amount of units+ '''++ order = models.IntegerField(verbose_name=_('Order'),+ blank=True,+ editable=False)+ '''+ The order of the ingredient within the meal+ '''++ def __str__(self):+ '''+ Return a more human-readable representation+ '''+ return u"{0}g ingredient {1}".format(self.amount, self.ingredient_id)++ def get_owner_object(self):+ '''+ Returns the object that has owner information+ '''+ return self.meal.plan+++@python_2_unicode_compatible+class LogItem(BaseMealItem, models.Model):+ '''+ An item (component) of a log+ '''+ plan = models.ForeignKey(NutritionPlan,+ verbose_name=_('Nutrition plan'),+ editable=False)+ '''+ The plan this log belongs to+ '''++ datetime = models.DateTimeField(auto_now=True)+ '''+ Time and date when the log was added+ '''++ comment = models.TextField(verbose_name=_('Comment'),+ blank=True)+ '''+ Comment field, for additional information+ '''++ ingredient = models.ForeignKey(Ingredient, verbose_name=_('Ingredient'))+ '''+ Ingredient+ '''++ weight_unit = models.ForeignKey(IngredientWeightUnit,+ verbose_name=_('Weight unit'),+ null=True,+ blank=True,+ )+ '''+ Weight unit used (grams, slices, etc.)+ '''++ amount = models.DecimalField(decimal_places=2,+ max_digits=6,+ verbose_name=_('Amount'),+ validators=[MinValueValidator(1),+ MaxValueValidator(1000)])+ '''+ The amount of units+ '''++ def __str__(self):+ '''+ Return a more human-readable representation+ '''+ return u"Diary entry {0}g ingredient {1}".format(self.amount, self.ingredient_id)++ def get_owner_object(self):+ '''+ Returns the object that has owner information+ '''+ return self.plan