diff --git a/cookbook/migrations/0028_auto_20200317_1901.py b/cookbook/migrations/0028_auto_20200317_1901.py new file mode 100644 index 00000000..08286af4 --- /dev/null +++ b/cookbook/migrations/0028_auto_20200317_1901.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.4 on 2020-03-17 18:01 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0027_ingredient_recipe'), + ] + + operations = [ + migrations.AlterField( + model_name='recipeingredient', + name='ingredient', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cookbook.Ingredient'), + ), + ] diff --git a/cookbook/migrations/0029_auto_20200317_1901.py b/cookbook/migrations/0029_auto_20200317_1901.py new file mode 100644 index 00000000..c3028db0 --- /dev/null +++ b/cookbook/migrations/0029_auto_20200317_1901.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.4 on 2020-03-17 18:01 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0028_auto_20200317_1901'), + ] + + operations = [ + migrations.AlterField( + model_name='recipeingredient', + name='unit', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cookbook.Unit'), + ), + ] diff --git a/cookbook/migrations/0030_recipeingredient_note.py b/cookbook/migrations/0030_recipeingredient_note.py new file mode 100644 index 00000000..1e8b4c40 --- /dev/null +++ b/cookbook/migrations/0030_recipeingredient_note.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.4 on 2020-03-17 18:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0029_auto_20200317_1901'), + ] + + operations = [ + migrations.AddField( + model_name='recipeingredient', + name='note', + field=models.CharField(blank=True, max_length=64, null=True), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index 69501111..58f1d662 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -134,10 +134,11 @@ class Ingredient(models.Model): class RecipeIngredient(models.Model): - ingredient = models.ForeignKey(Ingredient, on_delete=models.PROTECT, null=True) + ingredient = models.ForeignKey(Ingredient, on_delete=models.PROTECT) recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) - unit = models.ForeignKey(Unit, on_delete=models.PROTECT, null=True) + unit = models.ForeignKey(Unit, on_delete=models.PROTECT) amount = models.DecimalField(default=0, decimal_places=2, max_digits=16) + note = models.CharField(max_length=64, null=True, blank=True) def __str__(self): return str(self.amount) + ' ' + str(self.unit) + ' ' + str(self.ingredient) diff --git a/cookbook/templates/forms/edit_internal_recipe.html b/cookbook/templates/forms/edit_internal_recipe.html index 604f28a5..35292f2c 100644 --- a/cookbook/templates/forms/edit_internal_recipe.html +++ b/cookbook/templates/forms/edit_internal_recipe.html @@ -151,6 +151,7 @@ validator: "required", editor: select2UnitEditor }, + {title: "{% trans 'Note' %}", field: "note", editor: "input"}, { formatter: function (cell, formatterParams) { return "" @@ -188,6 +189,7 @@ ingredient__name: "{% trans 'Ingredient' %}", amount: "100", unit__name: "g", + note: "", id: Math.floor(Math.random() * 10000000), delete: false, }); diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py index 5c2f365c..1f76e9bf 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -86,6 +86,8 @@ def internal_recipe_update(request, pk): recipe_ingredient = RecipeIngredient() recipe_ingredient.recipe = recipe_instance + recipe_ingredient.note = i['note'] + if Ingredient.objects.filter(name=i['ingredient__name']).exists(): recipe_ingredient.ingredient = Ingredient.objects.get(name=i['ingredient__name']) else: @@ -118,7 +120,7 @@ def internal_recipe_update(request, pk): else: form = InternalRecipeForm(instance=recipe_instance) - ingredients = RecipeIngredient.objects.select_related('unit__name', 'ingredient__name').filter(recipe=recipe_instance).values('ingredient__name', 'unit__name', 'amount') + ingredients = RecipeIngredient.objects.select_related('unit__name', 'ingredient__name').filter(recipe=recipe_instance).values('ingredient__name', 'unit__name', 'amount', 'note') return render(request, 'forms/edit_internal_recipe.html', {'form': form, 'ingredients': json.dumps(list(ingredients)),