Adding inline formsets
An inline formset is a form within a form. It's a way to provide dynamic fields, for example, for additional personnel, comments, or objects. They are commonly used in combination with JavaScript code on the frontend to create or remove sets of fields as desired by the user. In the next exercise, we will expand upon the ModelFormClassCreateView
class to add our inline formset. This formset will capture prospective buyer information, to capture the first and last name of that lead. We will create an Add Another button for the user to add as many prospective buyers as they would like to. JavaScript is used to control creating and/or deleting the new DOM objects. It will also update the Django management form data in the process. You can build upon this concept to make your form more robust with added fields and controls for the user to manipulate inline formsets.
Follow the steps in the following sections to get started with inline formsets.