Best approach for forms with subforms

Hello,
My question is quite basic but I can’t find a clear answer; any help would be greatly appreciated.

What is the best approach to create of form with subforms? My situation is simple: the form and subforms are based on models, and a one-to-many foreign key exists between the 2.

I prefer using out of the box capabilities, class-based views and generic editing views.

Thanks a lot in advance,
C

In the general case (a form with subordinate forms), you’re looking for the formsets.

In the more specific case (subordinate forms based on a one-to-many relationship), you’re looking for model formsets.

You can certainly build Class-based views for working with these. However, most people find that trying to use formsets with the Django-provided generic editing views to be a bit frustrating. Those views really are designed around the idea of editing a single instance of one model. Formsets tend not to be a good “fit” for them.

When we use formsets, it’s either with an FBV or with a view directly inheriting from View.

(Also, you might want to search this site for “formsets”. There have been a lot of previous discussions here about them.)

Thank you very much Ken!
Indeed I have worked on a FBV and I could achieve my goals!
You helped me a lot, thanks!