基于Ajax的Django MultipleChoiceField

时间:2013-07-12 20:03:52

标签: jquery python django django-forms

有没有人知道Django的MultipleChoiceField的替代实现,而不是呈现为<select>,而是呈现为<input type="text">,它通过Ajax搜索加载选项(最好使用jquery),并存储选定的选项在隐藏的领域?

我有一个应用程序,用户需要在MultipleChoiceField中选择多个“人员”,但是可用的人数可以是数千,所以列出它们是不切实际的。

2 个答案:

答案 0 :(得分:1)

some_field = forms.MultipleChoiceField(
        choices=SOMECHOICE,
        widget=forms.SelectMultiple(),
        help_text='',
        label='',
        required=True,
        error_messages={'required': "This field is required (by default the value should be 'DEFAULT')."},
    )

答案 1 :(得分:0)

是的,这是django-ajax-selects。或者select2也是一个很好的图书馆。