Allow mealplan items to have no recipes

And display first line of notes in plan
This commit is contained in:
tourn 2020-04-13 19:56:00 +02:00
parent 83b5b6695c
commit 08cccfa133
3 changed files with 30 additions and 2 deletions

View File

@ -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'),
),
]

View File

@ -201,10 +201,16 @@ class MealPlan(models.Model):
MEAL_TYPES = ((BREAKFAST, _('Breakfast')), (LUNCH, _('Lunch')), (DINNER, _('Dinner')), (OTHER, _('Other')),) MEAL_TYPES = ((BREAKFAST, _('Breakfast')), (LUNCH, _('Lunch')), (DINNER, _('Dinner')), (OTHER, _('Other')),)
user = models.ForeignKey(User, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE)
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE, blank=True, null=True)
meal = models.CharField(choices=MEAL_TYPES, max_length=128, default=BREAKFAST) meal = models.CharField(choices=MEAL_TYPES, max_length=128, default=BREAKFAST)
note = models.TextField(blank=True) note = models.TextField(blank=True)
date = models.DateField() date = models.DateField()
def note_head(self):
try:
return self.note.split('\n')[0]
except:
return ''
def __str__(self): def __str__(self):
return self.meal + ' (' + str(self.date) + ') ' + str(self.recipe) return self.meal + ' (' + str(self.date) + ') ' + str(self.recipe)

View File

@ -76,7 +76,10 @@
<a class="mealplan-add-button" href="{% url 'new_meal_plan' %}?date={{ day_key|date:'Y-m-d' }}&meal={{ plan_key }}"><i class="fas fa-plus"></i></a> <a class="mealplan-add-button" href="{% url 'new_meal_plan' %}?date={{ day_key|date:'Y-m-d' }}&meal={{ plan_key }}"><i class="fas fa-plus"></i></a>
{% for mp in days_value %} {% for mp in days_value %}
<a href="{% url 'edit_meal_plan' mp.pk %}"><i class="fas fa-edit"></i></a> <a href="{% url 'edit_meal_plan' mp.pk %}"><i class="fas fa-edit"></i></a>
<a href="{% url 'view_recipe' mp.recipe.id %}">{{ mp.recipe.name }}</a><br/> {% if mp.recipe %}
<a href="{% url 'view_recipe' mp.recipe.id %}">{{ mp.recipe.name }}</a><br/>
{% endif %}
<span>{{ mp.note_head }}</span>
{% endfor %} {% endfor %}
</td> </td>
{% endfor %} {% endfor %}