some more recipe edit cleanup
This commit is contained in:
parent
6753a2c0b5
commit
e7227f84ca
@ -47,6 +47,8 @@ class ExternalRecipeForm(forms.ModelForm):
|
|||||||
|
|
||||||
|
|
||||||
class InternalRecipeForm(forms.ModelForm):
|
class InternalRecipeForm(forms.ModelForm):
|
||||||
|
ingredients = forms.CharField(widget=forms.HiddenInput(), required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Recipe
|
model = Recipe
|
||||||
fields = ('name', 'instructions', 'image', 'working_time', 'waiting_time', 'keywords')
|
fields = ('name', 'instructions', 'image', 'working_time', 'waiting_time', 'keywords')
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
<input type="hidden" id="ingredients_data_input" name="ingredients">
|
|
||||||
<hr>
|
<hr>
|
||||||
<button class="btn btn-success" type="submit"><i class="fas fa-save"></i> {% trans 'Save' %}</button>
|
<button class="btn btn-success" type="submit"><i class="fas fa-save"></i> {% trans 'Save' %}</button>
|
||||||
<a href="{% url 'redirect_delete' form.instance|get_class|lower form.instance.pk %}"
|
<a href="{% url 'redirect_delete' form.instance|get_class|lower form.instance.pk %}"
|
||||||
@ -153,7 +152,7 @@
|
|||||||
{title: "id", field: "id", visible: false}
|
{title: "id", field: "id", visible: false}
|
||||||
],
|
],
|
||||||
dataEdited: function (data) {
|
dataEdited: function (data) {
|
||||||
$('#ingredients_data_input').val(JSON.stringify(data))
|
$('#id_ingredients').val(JSON.stringify(data))
|
||||||
|
|
||||||
data.forEach(function (cur, i) {
|
data.forEach(function (cur, i) {
|
||||||
if (cur.delete) {
|
if (cur.delete) {
|
||||||
@ -171,13 +170,13 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// load initial value
|
// load initial value
|
||||||
$('#ingredients_data_input').val(JSON.stringify(data))
|
$('#id_ingredients').val(JSON.stringify(data))
|
||||||
|
|
||||||
document.getElementById("new_empty").addEventListener("click", function () {
|
document.getElementById("new_empty").addEventListener("click", function () {
|
||||||
data.push({
|
data.push({
|
||||||
name: "{% trans 'Ingredient' %}",
|
name: "{% trans 'Ingredient' %}",
|
||||||
amount: "100",
|
amount: "100",
|
||||||
unit: "g",
|
unit__name: "g",
|
||||||
id: Math.floor(Math.random() * 10000000),
|
id: Math.floor(Math.random() * 10000000),
|
||||||
delete: false,
|
delete: false,
|
||||||
});
|
});
|
||||||
|
@ -73,7 +73,7 @@ def internal_recipe_update(request, pk):
|
|||||||
|
|
||||||
recipe.save()
|
recipe.save()
|
||||||
|
|
||||||
form_ingredients = json.loads(form.data['ingredients'])
|
form_ingredients = json.loads(form.cleaned_data['ingredients'])
|
||||||
RecipeIngredients.objects.filter(recipe=recipe_instance).delete()
|
RecipeIngredients.objects.filter(recipe=recipe_instance).delete()
|
||||||
|
|
||||||
for i in form_ingredients:
|
for i in form_ingredients:
|
||||||
|
Loading…
Reference in New Issue
Block a user