Thanks!
On Jun 30, 9:28 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Try taking a look at
> this:http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/conf...
>
> On Jun 30, 2:09 am, Deniz Dogan <[EMAIL PROTECTED]> wrote:
>
> > Hello.
>
> > I'm trying to do what I like to call "dynamically set a form's field".
> > I want the user to input a dictionary e.g.
> > { 'intField' : 'int',
> > 'strField' : 'str' }
> > ...to the constructor of the form which will then create the fields
> > 'intField' (forms.IntegerField) and 'strField' (forms.CharField).
>
> > I have looked at Django's forms.py but I can't figure out how to do
> > it. This is what I have so far, which of course is not working:
>
> > class DynamicForm(forms.Form):
>
> > def __init__(self, data):
>
> > # The translations between types and fields.
> > field_from_type = {
> > 'int' : forms.IntegerField,
> > 'float' : forms.FloatField,
> > 'boolean' : forms.BooleanField,
> > 'string' : forms.CharField,
> > }
>
> > # Dynamically add fields and stuff.
> > for k, v in data.iteritems():
> > setattr(self, k, field_from_type[v]())
>
> > super(DynamicForm, self).__init__(data)
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---