Usage

The simplest way to use django-select2-forms is to use
select2.fields.ForeignKey and select2.fields.ManyToManyField in
place of django.db.models.ForeignKey and
django.db.models.ManyToManyField, respectively. These fields extend
their django equivalents and take the same arguments, along with extra
optional keyword arguments.

select2.fields.ForeignKey examples

In the following two examples, an “entry” is associated with only one
author. The example below does not use ajax, but instead performs
autocomplete filtering on the client-side using the <option>
elements (the labels of which are drawn from Author.__unicode__())
in an html <select>.

select2.fields.ManyToManyField examples

In the following basic example, entries can have more than one author.
This example does not do author name lookup via ajax, but populates
<option> elements in a <select> with Author.__unicode__()
for labels.

form field example

If you don’t need to use the ajax features of django-select2-forms
it is possible to use select2 on django forms without modifying your
models. The select2 formfields exist in the select2.fields module
and have the same class names as their standard django counterparts
(ChoiceField, MultipleChoiceField, ModelChoiceField,
ModelMultipleChoiceField). Here is the first ForeignKey example
above, done with django formfields.

API Documentation

License

The django code is licensed under the Simplified BSD
License and is
copyright The Atlantic Media Company. View the LICENSE file under
the root directory for complete license and copyright information.

The Select2 javascript library included is licensed under the Apache
Software Foundation License Version
2.0. View the file
select2/static/select2/select2/LICENSE for complete license and
copyright information about the Select2 javascript library.