I have a ModelForm class which can be used one or more times on a single page. E.g.:
class ProductForm(forms.ModelForm):
class Meta:
model = Product
exclude = ('prod_seq_number')
now when I want to use the form more than once on a single page, e.g.:
prodforms = []
for i in (range(nrofproducts)):
prodforms.append(ProductForm())
I can now pass the list prodforms to the template and the user can enter multiple products on the page. The variable nrofproducts is: 1, 2, 4, 8 or 16
This won’t work because I will get form elements with identical names. I need to be able to differentiate between the various form elements. So I need a way to modify the form attributes
for instance by appending the index ‘i’ from the loop in the view code the ‘name’ attribute of the form. Any help would be appreciated.
The reason for making a form layout like this is that a user can choose to see 1, 2, 4, 8 or 16 products on a single page and I want a entry form to resemble the layout which he will see when finished.
You really don’t want to do this. Simpler way of doing it would be to use Django Formset