Tough finding a form with dynamic fields out there

27 views
Skip to first unread message

Michael da Silva Pereira

unread,
May 30, 2012, 2:36:27 PM5/30/12
to django...@googlegroups.com
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:

Daniel Roseman

unread,
May 30, 2012, 4:14:14 PM5/30/12
to django...@googlegroups.com
So, compare this:


    def __init__(self, mailboxes, *args, **kwargs):

 with how you're calling it:
 
form = MboxReg(request.POST, int(mailboxes))


and you should see why you're getting this: 
 
Error:
Exception Value:
int() argument must be a string or a number, not 'QueryDict'
On the
  •         for i in range(int(mailboxes)):
-- Mike


-- 
DR.  

Mario Gudelj

unread,
May 31, 2012, 1:11:03 AM5/31/12
to django...@googlegroups.com
Daniel has point out the issue, but have a look at this speech from Django Con last year http://blip.tv/djangocon/advanced-django-form-usage-5573287. It has some great stuff in there.

-m

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/z68uQEeQ4fsJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply all
Reply to author
Forward
0 new messages