added recipe steps

This commit is contained in:
vabene1111
2020-06-25 22:38:17 +02:00
parent bf516d37a9
commit ae0928f85f
7 changed files with 170 additions and 80 deletions

1
.idea/recipes.iml generated
View File

@ -14,6 +14,7 @@
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/cookbook/tests/resources" />
<excludeFolder url="file://$MODULE_DIR$/staticfiles" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>

View File

@ -84,19 +84,15 @@ class InternalRecipeForm(forms.ModelForm):
class Meta:
model = Recipe
fields = ('name', 'instructions', 'image', 'working_time', 'waiting_time', 'keywords')
fields = ('name', 'image', 'working_time', 'waiting_time', 'keywords')
labels = {
'name': _('Name'),
'keywords': _('Keywords'),
'instructions': _('Instructions'),
'working_time': _('Preparation time in minutes'),
'waiting_time': _('Waiting time (cooking/baking) in minutes'),
}
widgets = {'keywords': MultiSelectWidget}
help_texts = {
'instructions': _('You can use markdown to format this field. See the <a href="/docs/markdown/">docs here</a>')
}
class ShoppingForm(forms.Form):

View File

@ -0,0 +1,14 @@
# Generated by Django 3.0.7 on 2020-06-25 20:09
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('cookbook', '0056_auto_20200625_2157'),
('cookbook', '0060_auto_20200625_2144'),
]
operations = [
]

View File

@ -0,0 +1,47 @@
# Generated by Django 3.0.7 on 2020-06-25 20:19
from django.db import migrations, models
def create_default_step(apps, schema_editor):
Recipe = apps.get_model('cookbook', 'Recipe')
Step = apps.get_model('cookbook', 'Step')
for r in Recipe.objects.filter(internal=True).all():
s = Step.objects.create(
instruction=r.instructions
)
for i in r.ingredients.all():
s.ingredients.add(i)
s.save()
r.steps.add(s)
r.save()
class Migration(migrations.Migration):
dependencies = [
('cookbook', '0061_merge_20200625_2209'),
]
operations = [
migrations.AlterField(
model_name='recipe',
name='ingredients',
field=models.ManyToManyField(blank=True, to='cookbook.Ingredient'),
),
migrations.CreateModel(
name='Step',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('kind', models.CharField(choices=[('TEXT', 'Text')], default='TEXT', max_length=16)),
('instruction', models.TextField(blank=True)),
('ingredients', models.ManyToManyField(blank=True, to='cookbook.Ingredient')),
],
),
migrations.AddField(
model_name='recipe',
name='steps',
field=models.ManyToManyField(blank=True, to='cookbook.Step'),
),
migrations.RunPython(create_default_step)
]

View File

@ -0,0 +1,21 @@
# Generated by Django 3.0.7 on 2020-06-25 20:30
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('cookbook', '0062_auto_20200625_2219'),
]
operations = [
migrations.RemoveField(
model_name='recipe',
name='ingredients',
),
migrations.RemoveField(
model_name='recipe',
name='instructions',
),
]

View File

@ -125,25 +125,6 @@ class Keyword(models.Model):
else:
return f"{self.name}"
class Recipe(models.Model):
name = models.CharField(max_length=128)
instructions = models.TextField(blank=True)
image = models.ImageField(upload_to='recipes/', blank=True, null=True)
storage = models.ForeignKey(Storage, on_delete=models.PROTECT, blank=True, null=True)
file_uid = models.CharField(max_length=256, default="")
file_path = models.CharField(max_length=512, default="")
link = models.CharField(max_length=512, null=True, blank=True)
cors_link = models.CharField(max_length=1024, null=True, blank=True)
keywords = models.ManyToManyField(Keyword, blank=True)
ingredients = models.ManyToManyField('Ingredient', blank=True, related_name='tmp_ingredients')
working_time = models.IntegerField(default=0)
waiting_time = models.IntegerField(default=0)
internal = models.BooleanField(default=False)
created_by = models.ForeignKey(User, on_delete=models.PROTECT)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
@ -158,7 +139,7 @@ class Unit(models.Model):
class Food(models.Model):
name = models.CharField(unique=True, max_length=128)
recipe = models.ForeignKey(Recipe, null=True, blank=True, on_delete=models.SET_NULL)
recipe = models.ForeignKey('Recipe', null=True, blank=True, on_delete=models.SET_NULL)
def __str__(self):
return self.name
@ -174,6 +155,32 @@ class Ingredient(models.Model):
return str(self.amount) + ' ' + str(self.unit) + ' ' + str(self.food)
class Step(models.Model):
TEXT = 'TEXT'
kind = models.CharField(choices=((TEXT, _('Text')),), default=TEXT, max_length=16)
instruction = models.TextField(blank=True)
ingredients = models.ManyToManyField(Ingredient, blank=True)
class Recipe(models.Model):
name = models.CharField(max_length=128)
image = models.ImageField(upload_to='recipes/', blank=True, null=True)
storage = models.ForeignKey(Storage, on_delete=models.PROTECT, blank=True, null=True)
file_uid = models.CharField(max_length=256, default="")
file_path = models.CharField(max_length=512, default="")
link = models.CharField(max_length=512, null=True, blank=True)
cors_link = models.CharField(max_length=1024, null=True, blank=True)
keywords = models.ManyToManyField(Keyword, blank=True)
steps = models.ManyToManyField(Step, blank=True)
working_time = models.IntegerField(default=0)
waiting_time = models.IntegerField(default=0)
internal = models.BooleanField(default=False)
created_by = models.ForeignKey(User, on_delete=models.PROTECT)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Comment(models.Model):
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
text = models.TextField()

View File

@ -103,7 +103,7 @@
{% endif %}
<div class="row">
{% if recipe.ingredients %}
{% if recipe.steps %}
<div class="col-md-6 order-md-1 col-sm-12 order-sm-2 col-12 order-2">
<div class="card">
<div class="card-body">
@ -124,7 +124,8 @@
</div>
<br/>
<table class="table table-sm">
{% for i in recipe.ingredients.all %}
{% for s in recipe.steps.all %}
{% for i in s.ingredients.all %}
{% if i.unit.name == 'Special:Header' %}
<tr>
<td style="padding-top: 8px!important; ">
@ -180,6 +181,7 @@
</tr>
{% endif %}
{% endfor %}
{% endfor %}
<!-- Bottom border -->
<tr>
<td></td>
@ -209,9 +211,11 @@
{% endif %}
<div style="font-size: large">
{% if recipe.instructions %}
{{ recipe.instructions | markdown | safe }}
{% for s in recipe.steps.all %}
{% if s.instruction %}
{{ s.instruction | markdown | safe }}
{% endif %}
{% endfor %}
</div>
{% if recipe.storage %}