Search code examples
djangodjango-formsmodelchoicefield

Django ModelChoiceField, thousands of options , not user friendly


I have a ModelChoiceField in my form:

customer = forms.ModelChoiceField(Customer.objects.all())

the problem is it renders as a drop down with hundreds of options and its difficult for users to find a customer, is there a way to overcome this???


Solution

  • You should use Bootstrap Select - which is a JQuery plugin that allows the searching of dropdown data by setting data-live-search="true" on the desired field.

    You can also set data-size="5" which would only show the first 5 options in the immediate dropdown field, other items are accessed via scrolling.

    (This will not help if the problem is the time it takes for this dropdown to load).