added ingredient notes + removed null constraints
This commit is contained in:
parent
1d562452df
commit
0c2b3d2d03
19
cookbook/migrations/0028_auto_20200317_1901.py
Normal file
19
cookbook/migrations/0028_auto_20200317_1901.py
Normal file
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
19
cookbook/migrations/0029_auto_20200317_1901.py
Normal file
19
cookbook/migrations/0029_auto_20200317_1901.py
Normal file
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
18
cookbook/migrations/0030_recipeingredient_note.py
Normal file
18
cookbook/migrations/0030_recipeingredient_note.py
Normal file
@ -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),
|
||||||
|
),
|
||||||
|
]
|
@ -134,10 +134,11 @@ class Ingredient(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class RecipeIngredient(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)
|
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)
|
amount = models.DecimalField(default=0, decimal_places=2, max_digits=16)
|
||||||
|
note = models.CharField(max_length=64, null=True, blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.amount) + ' ' + str(self.unit) + ' ' + str(self.ingredient)
|
return str(self.amount) + ' ' + str(self.unit) + ' ' + str(self.ingredient)
|
||||||
|
@ -151,6 +151,7 @@
|
|||||||
validator: "required",
|
validator: "required",
|
||||||
editor: select2UnitEditor
|
editor: select2UnitEditor
|
||||||
},
|
},
|
||||||
|
{title: "{% trans 'Note' %}", field: "note", editor: "input"},
|
||||||
{
|
{
|
||||||
formatter: function (cell, formatterParams) {
|
formatter: function (cell, formatterParams) {
|
||||||
return "<span style='color:red'><i class=\"fas fa-trash-alt\"></i></span>"
|
return "<span style='color:red'><i class=\"fas fa-trash-alt\"></i></span>"
|
||||||
@ -188,6 +189,7 @@
|
|||||||
ingredient__name: "{% trans 'Ingredient' %}",
|
ingredient__name: "{% trans 'Ingredient' %}",
|
||||||
amount: "100",
|
amount: "100",
|
||||||
unit__name: "g",
|
unit__name: "g",
|
||||||
|
note: "",
|
||||||
id: Math.floor(Math.random() * 10000000),
|
id: Math.floor(Math.random() * 10000000),
|
||||||
delete: false,
|
delete: false,
|
||||||
});
|
});
|
||||||
|
@ -86,6 +86,8 @@ def internal_recipe_update(request, pk):
|
|||||||
recipe_ingredient = RecipeIngredient()
|
recipe_ingredient = RecipeIngredient()
|
||||||
recipe_ingredient.recipe = recipe_instance
|
recipe_ingredient.recipe = recipe_instance
|
||||||
|
|
||||||
|
recipe_ingredient.note = i['note']
|
||||||
|
|
||||||
if Ingredient.objects.filter(name=i['ingredient__name']).exists():
|
if Ingredient.objects.filter(name=i['ingredient__name']).exists():
|
||||||
recipe_ingredient.ingredient = Ingredient.objects.get(name=i['ingredient__name'])
|
recipe_ingredient.ingredient = Ingredient.objects.get(name=i['ingredient__name'])
|
||||||
else:
|
else:
|
||||||
@ -118,7 +120,7 @@ def internal_recipe_update(request, pk):
|
|||||||
else:
|
else:
|
||||||
form = InternalRecipeForm(instance=recipe_instance)
|
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',
|
return render(request, 'forms/edit_internal_recipe.html',
|
||||||
{'form': form, 'ingredients': json.dumps(list(ingredients)),
|
{'form': form, 'ingredients': json.dumps(list(ingredients)),
|
||||||
|
Loading…
Reference in New Issue
Block a user