From 0bdde95b0659510a21a8920ba4eb64ef98415313 Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Mon, 10 Feb 2020 19:07:49 +0300 Subject: [PATCH] fix --- bots/modules/overlay.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bots/modules/overlay.py b/bots/modules/overlay.py index d054f21..5a8fa71 100644 --- a/bots/modules/overlay.py +++ b/bots/modules/overlay.py @@ -59,7 +59,17 @@ class OverlayBotModuleConfig(TelegramBotModuleConfig): def form_valid(view, bots_form, config_form): ImageFormSet = modelformset_factory(OverlayImage, form=ImageForm, extra=3, can_delete=True) formset = ImageFormSet(view.request.POST, view.request.FILES, queryset=config_form.instance.images.all()) - formset.save() + for form in formset.cleaned_data: + if form: + if form['DELETE']: + form['id'].delete() + elif form['image']: + if form['id']: + instance = form['id'] + instance.image = form['image'] + instance.save() + else: + OverlayImage.objects.create(config=config_form.instance, image=form['image']) class OverlayImage(models.Model):