Saving and updating a form

I have a built-in format that displays a maximum of 10 forms. But when I try to save / update the formset, these additional objects (which are empty in content) will also be saved. So every time the formset is saved / edited, these empty records keep going into the database. What is the reason?

+1


a source to share


1 answer


In your opinion, when you receive a POST with a formset, you should check each form to make sure it has changed (thus empty voids will be ignored). I've also included additional validation for deleted forms if you've enabled deletion:



for form in formset.forms:
  if form.has_changed():
       if not form in formset.deleted_forms:
            # Do something with this form

      

+9


a source







All Articles