Re: Adding a field to a form during runtime

2009-03-19 Thread Preston Timmons
Hi Marek, I think that your problem is that the make_car_form function returns a form class rather than an instance of that class. Once you have the class you still need to make an instance of it. Something like this might work: form_class = make_car_form(True) carForm = form_class() Preston

Re: Adding a field to a form during runtime

2009-03-19 Thread Thomas Guettler
Sorry, I can't help you here, since I don't create classes at runtime (*). I think using __init__() is better, and I guess you can solve your problem with it, too. (*) type('ContactForm', (forms.BaseForm, ), { 'base_fields': fields}) Marek W schrieb: > Thanks for your response. Probably the

Re: Adding a field to a form during runtime

2009-03-18 Thread Marek W
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

Re: Adding a field to a form during runtime

2009-03-18 Thread Thomas Guettler
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

Adding a field to a form during runtime

2009-03-18 Thread Marek W
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: