I would like to allow the visitor to add another email field. What do I need to do to allow the user to create another form?
#following the docs https://docs.djangoproject.com/en/1.5/topics/forms/formsets/#adding-additional-fields-to-a-formset #I don't see an add field button or instructions on how to create it #forms.py class BaseEmailFormSet(BaseFormSet): def add_fields(self, form, index): super(BaseEmailFormSet, self).add_fields(form, index) form.fields["email"] = forms.CharField() class AddMemberEmailForm(forms.Form): email = forms.EmailField() AddMemberEmailFormSet = formset_factory(AddMemberEmailForm, formset=BaseEmailFormSet) #views.py from .forms import AddMemberEmailFormSet email_formset = AddMemberEmailFormSet() if request.method == 'POST': email_formset = AddMemberEmailFormSet(request.POST, request.FILES) if email_formset.is_valid(): print "valid!" # pass 'email_formset': email_formset, to template #Template <form method="post">{% csrf_token %} {{email_formset.management_form}} <table> {% for form in email_formset %} {{form}} {%endfor%} </table> <input type="submit" value="{% trans "Add Member Email" %}" name="add_member_email" class="btn btn-info" /> </form>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment