diff --git a/.idea/recipes.iml b/.idea/recipes.iml index 752aa83d8..ba788b3de 100644 --- a/.idea/recipes.iml +++ b/.idea/recipes.iml @@ -14,6 +14,7 @@ + diff --git a/cookbook/forms.py b/cookbook/forms.py index 632e8eb2c..b8f6eab6f 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -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 docs here') - } class ShoppingForm(forms.Form): diff --git a/cookbook/migrations/0061_merge_20200625_2209.py b/cookbook/migrations/0061_merge_20200625_2209.py new file mode 100644 index 000000000..b3d7e90c9 --- /dev/null +++ b/cookbook/migrations/0061_merge_20200625_2209.py @@ -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 = [ + ] diff --git a/cookbook/migrations/0062_auto_20200625_2219.py b/cookbook/migrations/0062_auto_20200625_2219.py new file mode 100644 index 000000000..c852a0201 --- /dev/null +++ b/cookbook/migrations/0062_auto_20200625_2219.py @@ -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) + ] diff --git a/cookbook/migrations/0063_auto_20200625_2230.py b/cookbook/migrations/0063_auto_20200625_2230.py new file mode 100644 index 000000000..b10f99437 --- /dev/null +++ b/cookbook/migrations/0063_auto_20200625_2230.py @@ -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', + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index a7006cd6c..23f3f1250 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -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() diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index d83694f01..6c39e269c 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -103,7 +103,7 @@ {% endif %}
- {% if recipe.ingredients %} + {% if recipe.steps %}
@@ -124,61 +124,63 @@

- {% for i in recipe.ingredients.all %} - {% if i.unit.name == 'Special:Header' %} - - - + + - - - {% else %} - - + + + {% else %} + + - + - - - {% endif %} + + + + {% endif %} + {% endfor %} {% endfor %} @@ -209,9 +211,11 @@ {% endif %}
- {% if recipe.instructions %} - {{ recipe.instructions | markdown | safe }} - {% endif %} + {% for s in recipe.steps.all %} + {% if s.instruction %} + {{ s.instruction | markdown | safe }} + {% endif %} + {% endfor %}
{% if recipe.storage %}
- {{ i.note }} - + {% for s in recipe.steps.all %} + {% for i in s.ingredients.all %} + {% if i.unit.name == 'Special:Header' %} +
+ {{ i.note }} + -
-
- -
- +
+
+ +
+ +
- -
- {% if i.food.recipe %} - - {% endif %} - {{ i.food.name }} - {% if i.food.recipe %} - - {% endif %} + + {% if i.food.recipe %} + + {% endif %} + {{ i.food.name }} + {% if i.food.recipe %} + + {% endif %} - - {% if i.note %} - - - -
- {{ i.note }} -
- {% endif %} -
+ {% if i.note %} + + + +
+ {{ i.note }} +
+ {% endif %} +