jck
jck

Reputation: 2058

Django forms question

I want to generate a form from a model. However one of the fields in the model is a CharField, whose value is mostly "Option1" "Option2" or "Option3". If the user chooses "Other" I would like him to be able to type the value of the field.

How can I do this without having to write a whole form by hand?

Upvotes: 0

Views: 53

Answers (1)

BFil
BFil

Reputation: 13096

I think one only way could be to build your own widget and associate that widget with that CharField on a ModelForm

Django Widgets

UPDATE

Here's a sample custom widget implementation that inherits from TextInput:

http://www.kryogenix.org/days/2008/03/28/overriding-a-single-field-in-the-django-admin-using-newforms-admin

Upvotes: 1

Related Questions