[Django]-Save formset in an UpdateView

5👍

I solved the problem adding the post method to EntryUpdateView class:

def post(self, request, *args, **kwargs):
    self.object = self.get_object()
    form_class = self.get_form_class()
    form = self.get_form(form_class)
    qs = models.Meaning.objects.filter(entry=self.get_object())
    formsets = forms.MeaningFormSet(self.request.POST, queryset=qs)

    if form.is_valid():
        for fs in formsets:
            if fs.is_valid():
                fs.save()
        return self.form_valid(form)
    return self.form_invalid(form)

Leave a comment