views:

93

answers:

1

I am using the tutorial at http://proteus-tech.com/blog/cwt/django-dynamic-form/ for creating dynamic forms. It works perfect for creating the forms, but I would like to use some of the inputs with a Textarea widget. This is the code that is working from the tutorial, without any widgets defined:

from django import forms
form_config = {'title':'CharField', 'email':'EmailField', 'active':'BooleanField'}
dynamic_form = forms.Form()
for key in form_config.keys():
    dynamic_form.fields.insert(-1, key, getattr(forms, form_config.get(key))())
print dynamic_form.as_table()

I tried just adding the widget to the form_config:

form_config = {'title':'CharField(widget=forms.Textarea)'}

But that gives me a "module object has no attribute" error. Is there a way to add the widget to the dynamic form?

A: 

I found that there was a much better way to do this using type(). There is a great tutorial here: http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/

chris