Wednesday, May 30, 2012

Tough finding a form with dynamic fields out there

Hi,

Trying a form with dynamic fields, but having no luck. Also not finding any working examples out there :/

This is what I'm currently trying to use:

class MboxReg(forms.Form):
    def __init__(self, mailboxes, *args, **kwargs):
        super(MboxReg, self).__init__(*args, **kwargs)
        # now we add each question individually
        for i in range(int(mailboxes)):
            self.fields["mailbox_"+str(i)] = forms.CharField(max_length=128)
            self.fields["firstname_"+str(i)] = forms.CharField(max_length=128)
            self.fields["lastname_"+str(i)] = forms.CharField(max_length=128)
            self.fields["password_"+str(i)] = forms.CharField(max_length=128)

    domain = forms.CharField(max_length=128)
    customer = forms.CharField(max_length=128)
    licenses = forms.IntegerField()

Called with:
form = MboxReg(request.POST, int(mailboxes))


mailboxes is the amount of mailboxes requested to be added.

Error:
Exception Value:
int() argument must be a string or a number, not 'QueryDict'
On the
  •         for i in range(int(mailboxes)):
  • -- Mike



    Tradepage, now part of the Cloud Group, is an Authorised Google Apps for Business Reseller.  For only R485 per user per year, get Business Email, Calendars, Documents, syncing with mobile devices and much more. Find out more: http://www.tradepage.co.za/google-apps-for-business

    This email and all contents are subject to the following disclaimer:

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

    No comments:

    Post a Comment