Improving select fields in Django with django-ajax-selects
Replacing select lists with autocompleated ajax autocomplete widget
django-ajax-selects is a handy Django application that allows substituting select fields with ajax autocompleate fields. That can be done for example for Django admin panel and ForeignKey, ManyToMany fields. It solves the problems with select fields containing a lot of values.
- Download the django-ajax-selects package and install it (python setup.py install)
- Get jquery-plugin-autocomplete
- In settings.py add 'ajax_select' to INSTALLED_APPS
- In templates you will have to add few static files:
- iconic.css (opcjonalne)
ConfigurationTo use django-ajax-selects we need to configure one or more rules for searching records. All rules are stored in AJAX_LOOKUP_CHANNELS in the settings.py file, like so:
"ajax_related_articles" rule will look for record in the "article" model from "pages" application using "title" field values.Next step is to hookup that rule to the form in admin panel. In admin.py in the model config class add something like this: Where "Article" is the model name. As second arg for make_ajax_form you pass a dictionary where keys are model field names (for which this widget will be used) and values are the rule names defined in settings.py. In this example "related_articles" select field will be replaced with the ajax based widget.
Django-ajax-selects has more features - like applying that widget to other forms, or custom search rules. All those features are described on the project page.