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

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