Is it possible to have a formset in Django made up of heterogeneous forms considering that the formset_factory() function takes only one form class as parameter? Something like:
formset_factory(FormType1, FormType2,...)
There's nothing that fundamentally prevents the concept of formsets from working with multiple form classes, but the factories haven't been designed with that in mind. To achieve it you'd realistically have to write your own formset factory that overrides a lot of the existing API.
Consider this. You want a formset consisting on two different form classes. When the formset is instantiated, it needs to create min(current + extra, max_forms) forms. But how will it know which form class to create? It's easy if all the forms are the same, but for multiple classes you have to figure out a way of making this choice. I'm sure you can imagine how this will get rather complicated. The form wizards functionality might provide some possible ideas for how such an API could work, but it's a long shot,
I think finding an alternative approach might be the best choice in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With