Allow mealplan items to have no recipes
And display first line of notes in plan
This commit is contained in:
parent
83b5b6695c
commit
08cccfa133
19
cookbook/migrations/0031_mealplan_recipe_optional.py
Normal file
19
cookbook/migrations/0031_mealplan_recipe_optional.py
Normal 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'),
|
||||
),
|
||||
]
|
@ -201,10 +201,16 @@ class MealPlan(models.Model):
|
||||
MEAL_TYPES = ((BREAKFAST, _('Breakfast')), (LUNCH, _('Lunch')), (DINNER, _('Dinner')), (OTHER, _('Other')),)
|
||||
|
||||
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)
|
||||
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)
|
||||
|
@ -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>
|
||||
{% for mp in days_value %}
|
||||
<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 %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue
Block a user