skip to navigation
skip to content

Not Logged In

django-simple-autocomplete 0.4

App enabling the use of jQuery UI autocomplete widget for ModelChoiceFields with minimal configuration required.

Django Simple Autocomplete

App enabling the use of jQuery UI autocomplete widget for ModelChoiceFields with minimal configuration required.


  1. Install or add django-simple-autocomplete to your Python path.
  2. Add simple_autocomplete to your INSTALLED_APPS setting.
  3. Add (r’^simple-autocomplete/’, include(‘simple_autocomplete.urls’)) to urlpatterns.
  4. Ensure jQuery core, jQuery UI Javascript and jQuery UI CSS is loaded by your templates. Your jQueryUI bundle must include the autocomplete widget described at


Django by default renders a select widget (a.k.a. combobox or dropdown) for foreign key fields. You can change the widget to an autocomplete widget by adding the model to the SIMPLE_AUTOCOMPLETE_MODELS dictionary in your settings file. For instance, to use the autocomplete widget when selecting a user do:

SIMPLE_AUTOCOMPLETE = {'auth.user': {'search_field': 'username'}}

The dictionary format allows arbitrary parameters to be introduced in future. Parameter threshold indicates the minimum number of options required before the widget is rendered as an autocomplete widget. If the threshold is not met the default widget is rendered:

SIMPLE_AUTOCOMPLETE = {'auth.user': {'threshold': 10}}

Parameter max_items indicates the maximum number of matches to display in the autocomplete dropdown. It defaults to 10.:

SIMPLE_AUTOCOMPLETE = {'auth.user': {'max_items': 10}}

Parameter duplicate_format_function is a lambda function that enables a custom string should more than one item in the autocomplete dropdown have the same string value. It defaults to displaying the content type name. Set it using a lambda function, eg.:

SIMPLE_AUTOCOMPLETE = {'auth.user': {'duplicate_format_function': lambda obj, model, content_type: 'id: %s' %}}

The product attempts to use a field title for filtering the list. If the model has no field title then the first CharField is used. Eg. for the user model the field username is used.

The widget can be used implicitly in a form. The declaration of ModelChoiceField is all that is required:

class MyForm(forms.Form):
    user = forms.ModelChoiceField(queryset=User.objects.all(), initial=3)

The widget can be used explicitly in a form. In such a case you must provide an URL which returns results as JSON with format [(value, label), (value, label),…]. The initial and initial_display parameters are only required if there is a starting value:

from simple_autocomplete.widgets import AutoCompleteWidget

class MyForm(forms.Form):
    user = forms.ModelChoiceField(
            initial_display='John Smith'

The ability to specify an URL for the widget enables you to hook up to other more advanced autocomplete query engines if you wish.


Praekelt Foundation

  • Hedley Roos



  1. Deprecate SIMPLE_AUTOCOMPLETE_MODELS setting.
  2. Django 1.6.2 compatibility.


  1. Tests failing for Django 1.5. Pin to 1.4.x until that is fixed.
  2. Handle case where an item that is referenced by a multiselect has been deleted from the database.


  1. Allow search_field to be specified per model, in case the defaults don’t suffice.


  1. Fix unicode bug.


  1. max_items setting specifies maximum number of items to display in autocomplete dropdown.
  2. duplicate_format_function setting allows appending of a custom string if more than one item in the autocomplete dropdown has the same string value.


  1. Clear autoselect helper in some cases for cleaner UI.
  2. Use object string representation for display and not lookup fieldname.


  1. Add autocomplete widget for multiple selections
  2. Threshold setting to determine when to show autocomplete widget instead of normal widget


  1. Initial release.
File Type Py Version Uploaded on Size
django-simple-autocomplete-0.4.tar.gz (md5) Source 2014-02-26 13KB
django_simple_autocomplete-0.4-py2.7.egg (md5) Python Egg 2.7 2014-02-26 17KB
  • Downloads (All Versions):
  • 6 downloads in the last day
  • 135 downloads in the last week
  • 958 downloads in the last month