diff --git a/cookbook/admin.py b/cookbook/admin.py index 97103c5c2..664e048a1 100644 --- a/cookbook/admin.py +++ b/cookbook/admin.py @@ -51,7 +51,7 @@ admin.site.register(Food) class IngredientAdmin(admin.ModelAdmin): - list_display = ('recipe', 'food', 'amount', 'unit') + list_display = ('food', 'amount', 'unit') admin.site.register(Ingredient, IngredientAdmin) diff --git a/cookbook/migrations/0059_auto_20200625_2137.py b/cookbook/migrations/0059_auto_20200625_2137.py new file mode 100644 index 000000000..58781b3f0 --- /dev/null +++ b/cookbook/migrations/0059_auto_20200625_2137.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.7 on 2020-06-25 19:37 + +from django.db import migrations + + +def migrate_ingredients(apps, schema_editor): + Recipe = apps.get_model('cookbook', 'Recipe') + Ingredient = apps.get_model('cookbook', 'Ingredient') + + for r in Recipe.objects.all(): + for i in Ingredient.objects.filter(recipe=r).all(): + r.ingredients.add(i) + r.save() + + +class Migration(migrations.Migration): + dependencies = [ + ('cookbook', '0058_auto_20200625_2128'), + ] + + operations = [ + migrations.RunPython(migrate_ingredients), + ] diff --git a/cookbook/migrations/0060_auto_20200625_2144.py b/cookbook/migrations/0060_auto_20200625_2144.py new file mode 100644 index 000000000..8b74598ce --- /dev/null +++ b/cookbook/migrations/0060_auto_20200625_2144.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.7 on 2020-06-25 19:44 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0059_auto_20200625_2137'), + ] + + operations = [ + migrations.RemoveField( + model_name='ingredient', + name='recipe', + ), + migrations.AlterField( + model_name='sharelink', + name='uuid', + field=models.UUIDField(default=uuid.UUID('a7a91b2e-ad33-4159-a35e-828a5244ede9')), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index 09c75427a..866026762 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -165,7 +165,6 @@ class Food(models.Model): class Ingredient(models.Model): - recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) food = models.ForeignKey(Food, on_delete=models.PROTECT) unit = models.ForeignKey(Unit, on_delete=models.PROTECT) amount = models.DecimalField(default=0, decimal_places=16, max_digits=32) diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index 76661c123..d83694f01 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -103,7 +103,7 @@ {% endif %}
- {% if ingredients %} + {% if recipe.ingredients %}
@@ -124,7 +124,7 @@

- {% for i in ingredients %} + {% for i in recipe.ingredients.all %} {% if i.unit.name == 'Special:Header' %}
diff --git a/cookbook/views/views.py b/cookbook/views/views.py index 633bdb578..a814922eb 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -79,7 +79,6 @@ def recipe_view(request, pk, share=None): messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!')) return HttpResponseRedirect(reverse('index')) - ingredients = Ingredient.objects.filter(recipe=recipe).all() comments = Comment.objects.filter(recipe=recipe) if request.method == "POST": @@ -116,7 +115,7 @@ def recipe_view(request, pk, share=None): ViewLog.objects.create(recipe=recipe, created_by=request.user) return render(request, 'recipe_view.html', - {'recipe': recipe, 'ingredients': ingredients, 'comments': comments, 'comment_form': comment_form, + {'recipe': recipe, 'comments': comments, 'comment_form': comment_form, 'bookmark_form': bookmark_form})