This commit is contained in:
bakatrouble 2020-02-10 19:07:49 +03:00
parent fd62d22cbb
commit 0bdde95b06

View File

@ -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):