Package: django-simple-autocomplete
Django Simple AutocompleteApp enabling the use of jQuery UI autocomplete widget for ModelChoiceFields with minimal configuration required.ContentsDjango Simple AutocompleteInstallationUsageAuthorsChangelog1.111.9.11.90.5.20.5.10.50.40.3.30.3.20.3.10.30.20.10.0.1InstallationInstall or adddjango-simple-autocompleteto your Python path.Addsimple_autocompleteto yourINSTALLED_APPSsetting.Add (r’^simple-autocomplete/’, include(‘simple_autocomplete.urls’, namespace=’simple_autocomplete’)) to urlpatterns.Add<scriptsrc="{{STATIC_URL}}simple_autocomplete/jquery-ui.js"></script>and<linkrel="stylesheet"href="{{STATIC_URL}}simple_autocomplete/jquery-ui.css"/>to your template.
You may need to override eg.templates/admin/base.html. If you already have jQuery UI installed for
your site you may skip this step.UsageDjango 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.
Parameterthresholdindicates 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}}Parametermax_itemsindicates the maximum number of matches to display in the autocomplete dropdown. It defaults to 10.:SIMPLE_AUTOCOMPLETE = {'auth.user': {'max_items': 10}}Parameterduplicate_format_functionis 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' % obj.id}}The product attempts to use a fieldtitlefor filtering the list. If the
model has no fieldtitlethen the first CharField is used. Eg. for the user
model the fieldusernameis used.The widget can be used implicitly in a form. The declaration ofModelChoiceFieldis 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),…].
Theinitialandinitial_displayparameters are only required if there is
a starting value:from simple_autocomplete.widgets import AutoCompleteWidget

class MyForm(forms.Form):
    user = forms.ModelChoiceField(
        queryset=User.objects.all(),
        initial=3,
        widget=AutoCompleteWidget(
            url='/custom-json-query',
            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.AuthorsPraekelt ConsultingHedley RoosChangelog1.11Django 1.11 compatibility. Correct use of django.jQuery.1.9.1Ensure the static files are also deployed.1.9Django 1.9 compatibility. Support for previous versions has been dropped.0.5.2If a search field is supplied then the dropdown now shows those attributes, not the objects string representation.0.5.1Only apply autocomplete in cases where a default widget isn’t supplied. This enables the product to work harmoniously with eg. Grappelli’s autocomplete.0.5Preserve sort order of multiple choice values.0.4DeprecateSIMPLE_AUTOCOMPLETE_MODELSsetting.Django 1.6.2 compatibility.0.3.3Tests failing for Django 1.5. Pin to 1.4.x until that is fixed.Handle case where an item that is referenced by a multiselect has been deleted from the database.0.3.2Allowsearch_fieldto be specified per model, in case the defaults don’t suffice.0.3.1Fix unicode bug.0.3max_itemssetting specifies maximum number of items to display in autocomplete dropdown.duplicate_format_functionsetting allows appending of a custom string if more than one item in the autocomplete dropdown has the same string value.0.2Clear autoselect helper in some cases for cleaner UI.Use object string representation for display and not lookup fieldname.0.1Add autocomplete widget for multiple selectionsThreshold setting to determine when to show autocomplete widget instead of normal widget0.0.1Initial release.