[Fixed]-Django ModelChoiceField, thousands of options , not user friendly

1👍

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).

👤drew

0👍

This is incorrect way to do what you’re trying to accomplish here.

If you’re displaying more than 20 or so customer then the UI would clutter and it would be hard to find the customer with ChoiceField. You’d probably want to index the data from your DB into a full text search engine such as ElasticSearch which is based on Lucene and then use AJAX to query particular customer by it’s name or any unique identifier.

Needless to say here that instead of the ChoiceField, now your form will have a text field and as soon as user tries to fill in the name, the AJAX calls fetches the customers from ElasticSearch and renders the result.

Leave a comment