diff --git a/cookbook/forms.py b/cookbook/forms.py
index 52eb993ed..422b89d8b 100644
--- a/cookbook/forms.py
+++ b/cookbook/forms.py
@@ -242,8 +242,17 @@ class RecipeBookForm(forms.ModelForm):
class MealPlanForm(forms.ModelForm):
+
+ def clean(self):
+ cleaned_data = super(MealPlanForm, self).clean()
+
+ if cleaned_data['title'] == '' and cleaned_data['recipe'] is None:
+ raise forms.ValidationError(_('You must provide at least a recipe or a title.'))
+
+ return cleaned_data
+
class Meta:
model = MealPlan
- fields = ('recipe', 'meal', 'note', 'date')
+ fields = ('recipe', 'title', 'meal', 'note', 'date')
widgets = {'recipe': SelectWidget, 'date': DateWidget}
diff --git a/cookbook/migrations/0031_mealplan_recipe_optional.py b/cookbook/migrations/0041_auto_20200502_1446.py
similarity index 59%
rename from cookbook/migrations/0031_mealplan_recipe_optional.py
rename to cookbook/migrations/0041_auto_20200502_1446.py
index 76a8a1b67..84f5aa4eb 100644
--- a/cookbook/migrations/0031_mealplan_recipe_optional.py
+++ b/cookbook/migrations/0041_auto_20200502_1446.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.0.4 on 2020-04-13 17:48
+# Generated by Django 3.0.5 on 2020-05-02 12:46
from django.db import migrations, models
import django.db.models.deletion
@@ -7,10 +7,15 @@ import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
- ('cookbook', '0030_recipeingredient_note'),
+ ('cookbook', '0040_auto_20200502_1433'),
]
operations = [
+ migrations.AddField(
+ model_name='mealplan',
+ name='title',
+ field=models.CharField(blank=True, default='', max_length=64),
+ ),
migrations.AlterField(
model_name='mealplan',
name='recipe',
diff --git a/cookbook/models.py b/cookbook/models.py
index 0f1763654..b127f96d7 100644
--- a/cookbook/models.py
+++ b/cookbook/models.py
@@ -47,7 +47,7 @@ class UserPreference(models.Model):
PLAN = 'PLAN'
BOOKS = 'BOOKS'
- PAGES = ((SEARCH, _('Search')), (PLAN, _('Meal-Plan')), (BOOKS, _('Books')), )
+ PAGES = ((SEARCH, _('Search')), (PLAN, _('Meal-Plan')), (BOOKS, _('Books')),)
# Search Style
SMALL = 'SMALL'
@@ -221,16 +221,14 @@ class MealPlan(models.Model):
MEAL_TYPES = ((BREAKFAST, _('Breakfast')), (LUNCH, _('Lunch')), (DINNER, _('Dinner')), (OTHER, _('Other')),)
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE, blank=True, null=True)
+ title = models.CharField(max_length=64, blank=True, default='')
created_by = models.ForeignKey(User, 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)
+ if self.title:
+ return self.title
+ return str(self.recipe)
+
diff --git a/cookbook/templates/meal_plan.html b/cookbook/templates/meal_plan.html
index 653ca57fd..b4f8f72cf 100644
--- a/cookbook/templates/meal_plan.html
+++ b/cookbook/templates/meal_plan.html
@@ -77,7 +77,7 @@
{% for mp in days_value %}
{% if mp.recipe %}
- {{ mp.recipe.name }}
+ {{ mp }}
{% endif %}
{{ mp.note_head }}
{% endfor %}