views:

33

answers:

1

I'm using a third-party app (Satchmo) and I want to change a text field to a dropdown with some preset options plus a text field where the user can fill in their own value.

I know how to mess with the admin model to change the field to use a dropdown of presets, but not how to preserve the users ability to specify the value themselves.

I suppose another option would be to use javascript to add a suggest feature to the text field, but I prefer the former.

A: 

Write a custom form field for it.

Documentation: http://code.djangoproject.com/wiki/CustomFormFields

Basically, you need to write methods to render, validate and convert post data.

You can define the javascript required to present the textbox when a particular dropdown value is chosen, and that script is also auto rendered by {{form.media}}

Lakshman Prasad
Mmh have you read the first sentence on the page you linked to? : *Note: this information is obsolete and no longer applies to Django*
Felix Kling
That was the first google result actually. But the way to write form fields is not too different. Here you go: http://docs.djangoproject.com/en/dev/ref/forms/fields/#creating-custom-fields Its more or less the same.
Lakshman Prasad