2012-09-14 06:34:36 +00:00
|
|
|
===========
|
|
|
|
|
Get Started
|
|
|
|
|
===========
|
|
|
|
|
|
|
|
|
|
Overview
|
|
|
|
|
--------
|
|
|
|
|
|
|
|
|
|
.. automodule:: django_select2
|
|
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
Installation
|
|
|
|
|
------------
|
|
|
|
|
|
2015-09-25 20:11:50 +00:00
|
|
|
1. Install ``django_select2``::
|
2012-09-14 06:34:36 +00:00
|
|
|
|
|
|
|
|
pip install django_select2
|
|
|
|
|
|
2015-09-25 20:11:50 +00:00
|
|
|
2. Add ``django_select2`` to your ``INSTALLED_APPS`` in your project settings.
|
2012-09-14 06:34:36 +00:00
|
|
|
|
|
|
|
|
|
2016-02-04 10:47:21 +00:00
|
|
|
3. Add ``django_select`` to your ``urlconf`` **if** you use any
|
2016-02-03 18:47:40 +00:00
|
|
|
:class:`ModelWidgets <.django_select2.forms.ModelSelect2Mixin>`::
|
2013-11-20 00:44:28 +00:00
|
|
|
|
2013-09-29 08:22:45 +00:00
|
|
|
url(r'^select2/', include('django_select2.urls')),
|
2012-09-14 06:34:36 +00:00
|
|
|
|
2018-03-19 11:09:54 +00:00
|
|
|
Quick Start
|
|
|
|
|
-----------
|
|
|
|
|
|
|
|
|
|
Here is a quick example to get you started:
|
|
|
|
|
|
|
|
|
|
0. Follow the installation instructions above.
|
|
|
|
|
|
|
|
|
|
1. Add a select2 widget to the form. For example if you wanted Select2 with multi-select you would use
|
|
|
|
|
``Select2MultipleWidget``
|
|
|
|
|
Replacing::
|
|
|
|
|
|
|
|
|
|
class MyForm(forms.Form):
|
|
|
|
|
things = ModelMultipleChoiceField(queryset=Thing.objects.all())
|
|
|
|
|
|
|
|
|
|
with::
|
|
|
|
|
|
|
|
|
|
class MyForm(forms.Form):
|
|
|
|
|
things = ModelMultipleChoiceField(queryset=Thing.objects.all(), widget=Select2MultipleWidget)
|
|
|
|
|
|
|
|
|
|
2. Add the CSS to the ``head`` of your Django template::
|
|
|
|
|
|
|
|
|
|
{{ form.media.css }}
|
|
|
|
|
|
|
|
|
|
3. Add the JavaScript to the end of the ``body`` of your Django template::
|
|
|
|
|
|
|
|
|
|
{{ form.media.js }}
|
|
|
|
|
|
|
|
|
|
4. Done - enjoy the wonders of Select2!
|
2013-11-08 02:34:03 +00:00
|
|
|
|
2012-09-14 06:34:36 +00:00
|
|
|
External Dependencies
|
|
|
|
|
---------------------
|
|
|
|
|
|
2015-09-25 20:11:50 +00:00
|
|
|
* jQuery version 2
|
|
|
|
|
This is not included in the package since it is expected
|
|
|
|
|
that in most scenarios this would already be available.
|
2012-09-14 06:34:36 +00:00
|
|
|
|
|
|
|
|
Example Application
|
|
|
|
|
-------------------
|
2015-09-25 20:11:50 +00:00
|
|
|
Please see ``tests/testapp`` application.
|
|
|
|
|
This application is used to manually test the functionalities of this package.
|
|
|
|
|
This also serves as a good example.
|