Getting Django easy-select2 to include JQuery and friends

Select2 is how you get boring dropdown lists:
dropdown

to look like this:
select2

And django-easy-select2 is a little Django app that quickly turns that on for whatever widgets in your form you choose.

  1. Add easy_select2 to INSTALLED_APPS
  2. In your forms.py:
    from easy_select2.widgets import Select2, Select2Multiple
    When using the widget, don’t just use the class name, provide an instance, like Select2()

If only it were that easy. The documentation for easy-select2 forgot to mention:

  1. Include {{ form.media }} in the head section of your template

Otherwise jQuery and the other magic stuff that actually does the list hiding and searching/whatever doesn’t actually load in the browser.

Leave a Reply

Your email address will not be published. Required fields are marked *