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
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 reas
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
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 Ca
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:
5 matches
Mail list logo