I'm trying to add multiple instances of the same form on one page,
each with its own submit button. I know how to use the 'prefix'
argument for a form to differentiate between forms, but I can't figure
out how to get the right data when it is POST'ed back (see view.py
below). Somehow the form stays invalid, no matter what I try. Any
suggestions what I may be doing wrong?

Thanks!

=models.py=======================
class Invite(models.Model):
    invitation    = models.ForeignKey(Invitation, verbose_name=_
('User'))
    email_address = models.EmailField(_('email address'))
    status        = models.CharField(_('RSVP status'), max_length=1,
choices=settings.INVITE_RESPONSE_CHOICES)
========================


=views.py===================
def invite_resp(request):
    invites = Invite.objects.all()
    if request.method == 'POST':
        invite_formz = [InviteForm(request.POST, prefix=str(index),
instance=invite) for index, invite in enumerate(invites)]
        if all([invite_form.is_valid() for invite_form in
invite_formz]):
            invite = invite_form.save()
            return HttpResponseRedirect('/')
    invite_forms = [InviteForm(instance=invite) for index, invite in
enumerate(invites)]
    return render_to_response('invite_resp.html', {'invite_forms':
invite_forms}, context_instance=RequestContext(request))
========================

=forms.py================
class InviteForm(forms.ModelForm):

    def __init__(self, label, *args, **kwargs):
        super(InviteForm, self).__init__(*args, **kwargs)
        self.fields['status'].label = label

    class Meta:
        model = Invite
        exclude = ('invitation', 'email_address')
========================

=page.html=======================
{% block content %}
        {% for invite_form in invite_forms %}
            <form action="." method="POST"
name="{{ invite_form.status.label}}">
                <table>
                    <tr>
                        <th>{{ invite_form.status.label }}</th>
                        <td>{{ invite_form.status }}</td>
                        <td><input type="submit" value="{% trans
'Submit' %}"></td>
                    </tr>
                </table>
            </form>
        {% endfor %}
{% endblock %}
========================





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to