python 2.7 - Flexible number of form fields in Django forms -
i create form contains several fields this
class mainform(forms.form): name = forms.charfield(label='name') comment = forms.charfield(label='comment')
right have 1 field "comment". want have option user can add more comment fields form through website.
so need to:
1) define form more flexible such there can n comment fields. (default n=1)
2) define method add new comment fields.
3) define utility functions, cleaning form fields, flexible can handle dynamic number of comment fields.
i ideas of how set in clean way.
formsets solution this:
https://docs.djangoproject.com/en/1.6/topics/forms/formsets/
it handle 1 , 3 cleanly. have had write javascript in past inject fields in form when clicking add. after submit django takes care of rest.
Comments
Post a Comment