diff --git a/cookbook/migrations/0031_mealplan_recipe_optional.py b/cookbook/migrations/0031_mealplan_recipe_optional.py new file mode 100644 index 000000000..76a8a1b67 --- /dev/null +++ b/cookbook/migrations/0031_mealplan_recipe_optional.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.4 on 2020-04-13 17:48 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0030_recipeingredient_note'), + ] + + operations = [ + migrations.AlterField( + model_name='mealplan', + name='recipe', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='cookbook.Recipe'), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index f0611a1f7..0f1763654 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -220,11 +220,17 @@ class MealPlan(models.Model): OTHER = 'OTHER' MEAL_TYPES = ((BREAKFAST, _('Breakfast')), (LUNCH, _('Lunch')), (DINNER, _('Dinner')), (OTHER, _('Other')),) + recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE, blank=True, null=True) created_by = models.ForeignKey(User, on_delete=models.CASCADE) - recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) meal = models.CharField(choices=MEAL_TYPES, max_length=128, default=BREAKFAST) note = models.TextField(blank=True) date = models.DateField() + def note_head(self): + try: + return self.note.split('\n')[0] + except: + return '' + def __str__(self): return self.meal + ' (' + str(self.date) + ') ' + str(self.recipe) diff --git a/cookbook/templates/meal_plan.html b/cookbook/templates/meal_plan.html index 0691e473b..653ca57fd 100644 --- a/cookbook/templates/meal_plan.html +++ b/cookbook/templates/meal_plan.html @@ -76,7 +76,10 @@ {% for mp in days_value %} - {{ mp.recipe.name }}
+ {% if mp.recipe %} + {{ mp.recipe.name }}
+ {% endif %} + {{ mp.note_head }} {% endfor %} {% endfor %}