The widgets in django-selectable define the media they need as described in the
Django documentation on Form Media.
That means to include the javascript and css you need to make the widgets work you
can include {{form.media.css}} and {{form.media.js}} in your template. This is
assuming your form is called form in the template context. For more information
please check out the Django documentation.

The jQuery and jQuery UI libraries are not included in the distribution but must be included
in your templates. However there is a template tag to easily add these libraries from
the from the Google CDN.

{% load selectable_tags %}
{% include_jquery_libs %}

By default these will use jQuery v1.11.2 and jQuery UI v1.11.3. You can customize the versions
used by pass them to the tag. The first version is the jQuery version and the second is the
jQuery UI version.

This lookups extends selectable.base.ModelLookup and defines two things: one is
the model on which we will be searching and the other is the field which we are searching.
This syntax should look familiar as it is the same as the field lookup syntax
for making queries in Django.

Below this definition we will register our lookup class.

registry.register(FruitLookup)

Note

You should only register your lookup once. Attempting to register the same lookup class
more than once will lead to LookupAlreadyRegistered errors. A common problem related to the
LookupAlreadyRegistered error is related to inconsistant import paths in your project.
Prior to Django 1.4 the default manage.py allows for importing both with and without
the project name (i.e. frommyproject.myappimportlookups or frommyappimportlookups).
This leads to the lookup.py file being imported twice and the registration code
executing twice. Thankfully this is no longer the default in Django 1.4. Keeping
your import consistant to include the project name (when your app is included inside the
project directory) will avoid these errors.

Now that we have a working lookup we will define a form which uses it:

fromdjangoimportformsfromselectable.formsimportAutoCompleteWidgetfrom.lookupsimportFruitLookupclassFruitForm(forms.Form):autocomplete=forms.CharField(label='Type the name of a fruit (AutoCompleteWidget)',widget=AutoCompleteWidget(FruitLookup),required=False,)

This replaces the default widget for the CharField with the AutoCompleteWidget.
This will allow the user to fill this field with values taken from the names of
existing Fruit models.

And that’s pretty much it. Keep on reading if you want to learn about the other
types of fields and widgets that are available as well as defining more complicated
lookups.