Reputation: 2645
I have a simple use case. I have 3 models foo, foo1 and foo2. I have created model forms for them. Now in a page I have these forms together on that page.
PROBLEM : The user has the option to click on a "ADD" button. Once he clicks on it he will be able to add 1 more foo2 i.e. 1 more foo2 form will open or be displayed. How should I do this ? i.e. how do I add a modelform dynamically ?
Edit:
This can be done using jquery. But my question is how do I differentiate it in the view ? Should I use prefix ? i.e. should I add dynamic prefix to the forms that are being created ?
Upvotes: 0
Views: 59
Reputation: 599956
As Rohan says in the comments, if you have more than one of the same kind of form on a page, you should be using formsets. Each form within the formset has its own prefix which includes an ID which you can simply increment with your Javascript.
Upvotes: 1