Thanks for your response. Probably the reason was I didn't update a database, because now(after making syncdb) it works correctly. But by the time I've found a second problem:
while to create a dynamic form this way: def make_car_form(extra): fields = { 'carType' : forms.CharField() } if extra: fields['extraField'] = forms.CharField() return type('ContactForm', (forms.BaseForm, ), { 'base_fields': fields }) View method: (...) carForm = make_car_form(True) (...) then on the page there aren't any fields, whether calling make_car_form with extra=True or extra=False. Regards, Marek 2009/3/18 Thomas Guettler <h...@tbz-pariv.de> > > Hi, > > your code looks correct. > > You can try to debug it. Maybe insert > assert False, self.fields into __init__() > Do the fields from the model exist? > > Thomas > > Marek W schrieb: > > Hi, I would like to add a field to a form dynamically. I'm using Django > > 1.0.2. > > > > Here's my view code: > > > > class CarForm(ModelForm): > > def __init__(self, *args, **kwargs): > > super(CarForm, self).__init__(*args, **kwargs) > > self.fields['extraField'] = forms.CharField() > > > > class Meta: > > model = Car > ... > > > I took this idea from > > http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/. When I try to > view > > the page, when there's my own __init__ method in CarForm class, then the > car > > form doesn't contain any field. When i remove the __init__ method, > > everything works correctly. How to add a field to a form during a > runtime ? > > > -- > Thomas Guettler, http://www.thomas-guettler.de/ > E-Mail <http://www.thomas-guettler.de/%0AE-Mail>: guettli (*) > thomas-guettler + de > > > > -- Pozdrawiam, Marek Wawrzyczek --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---