some more recipe edit cleanup

This commit is contained in:
vabene1111 2020-02-02 22:52:25 +01:00
parent 6753a2c0b5
commit e7227f84ca
3 changed files with 6 additions and 5 deletions

View File

@ -47,6 +47,8 @@ class ExternalRecipeForm(forms.ModelForm):
class InternalRecipeForm(forms.ModelForm):
ingredients = forms.CharField(widget=forms.HiddenInput(), required=False)
class Meta:
model = Recipe
fields = ('name', 'instructions', 'image', 'working_time', 'waiting_time', 'keywords')

View File

@ -32,7 +32,6 @@
{% endif %}
{% endfor %}
<input type="hidden" id="ingredients_data_input" name="ingredients">
<hr>
<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 %}"
@ -153,7 +152,7 @@
{title: "id", field: "id", visible: false}
],
dataEdited: function (data) {
$('#ingredients_data_input').val(JSON.stringify(data))
$('#id_ingredients').val(JSON.stringify(data))
data.forEach(function (cur, i) {
if (cur.delete) {
@ -171,13 +170,13 @@
});
// load initial value
$('#ingredients_data_input').val(JSON.stringify(data))
$('#id_ingredients').val(JSON.stringify(data))
document.getElementById("new_empty").addEventListener("click", function () {
data.push({
name: "{% trans 'Ingredient' %}",
amount: "100",
unit: "g",
unit__name: "g",
id: Math.floor(Math.random() * 10000000),
delete: false,
});

View File

@ -73,7 +73,7 @@ def internal_recipe_update(request, pk):
recipe.save()
form_ingredients = json.loads(form.data['ingredients'])
form_ingredients = json.loads(form.cleaned_data['ingredients'])
RecipeIngredients.objects.filter(recipe=recipe_instance).delete()
for i in form_ingredients: