@@ -8,6 +8,12 @@ Overview
88.. automodule :: django_select2
99 :members:
1010
11+ Assumptions
12+ -----------
13+
14+ * You have a running Django up and running.
15+ * You have form fully working without Django-Select2.
16+
1117Installation
1218------------
1319
@@ -17,11 +23,12 @@ Installation
1723
18242. Add ``django_select2 `` to your ``INSTALLED_APPS `` in your project settings.
1925
26+ 3. Add ``django_select `` to your ``urlconf ``::
2027
21- 3. Add ``django_select `` to your ``urlconf `` **if ** you use any
22- :class: `ModelWidgets <.django_select2.forms.ModelSelect2Mixin> `::
28+ path('select2/', include('django_select2.urls')),
2329
24- url(r'^select2/', include('django_select2.urls')),
30+ You can safely skip this one if you do not use any
31+ :class:`ModelWidgets <.django_select2.forms.ModelSelect2Mixin>`
2532
2633Quick Start
2734-----------
@@ -30,19 +37,22 @@ Here is a quick example to get you started:
3037
31380. Follow the installation instructions above.
3239
33- 1. Add a select2 widget to the form. For example if you wanted Select2 with multi-select you would use
34- ``Select2MultipleWidget ``
35- Replacing::
40+ 1. Replace native Django forms widgets with one of the several ``django_select2.form `` widgets.
41+ Start by importing them into your ``forms.py ``, right next to Django own ones::
3642
37- class MyForm( forms.Form):
38- things = ModelMultipleChoiceField(queryset=Thing.objects.all())
43+ from django import forms
44+ from django_select2 import forms as s2forms
3945
40- with::
46+ Then let's assume you have a model with a choice, a :class: `.ForeignKey `, and a
47+ :class: `.ManyToManyField `, you would add this information to your Form Meta
48+ class::
4149
42- from django_select2.forms import Select2MultipleWidget
43-
44- class MyForm(forms.Form):
45- things = ModelMultipleChoiceField(queryset=Thing.objects.all(), widget=Select2MultipleWidget)
50+ widgets = {
51+ 'category': s2forms.Select2Widget,
52+ 'author': s2forms.ModelSelect2Widget(model=auth.get_user_model(),
53+ search_fields=['first_name__istartswith', 'last_name__icontains']),
54+ 'attending': s2forms.ModelSelect2MultipleWidget …
55+ }
4656
47572. Add the CSS to the ``head `` of your Django template::
4858
0 commit comments