开发者

How can I let a user select from a dropdown OR provide their own value in the Django admin?

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.


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}}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜