--To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Y_DfzKjYiYwJ.
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
You don't show much of your code, but I presume you have called
formset.is_valid() at this point?
If so, this pattern is pretty canonical:
if formset.is_valid():
for form in formset:
if form.is_valid() and not form.empty_permitted:
form.save()
Extra forms in a formset are all instantiated with empty_permitted=True.
There are other things to be aware of though. This logic will not take
into account deleted forms etc, which is why there is a
BaseModelFormSet with the right behaviour baked into it's save()
method.
Cheers
Tom
New forms will have form.empty_permitted=True, unmodified forms will
return True from form.has_changed(). This should be enough to skip
over blank new forms.
Cheers
Tom
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/aKliGdMNqGwJ.