added title field and custom validation

This commit is contained in:
vabene1111
2020-05-02 14:53:09 +02:00
parent fd4354f16d
commit e9da17151a
4 changed files with 24 additions and 12 deletions

View File

@ -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}