Skip to content

Commit d63f410

Browse files
mfrascacodingjoe
authored andcommitted
Improve getting started documentation (applegrew#542)
1 parent 5680f0d commit d63f410

File tree

7 files changed

+60
-21
lines changed

7 files changed

+60
-21
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ stages:
4141

4242
jobs:
4343
include:
44-
- python: "3.5"
44+
- python: "3.7"
4545
env: TOXENV=docs
4646
addons:
4747
apt:

CONTRIBUTING.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Contributing
2+
============
3+
4+
This package uses the pyTest test runner. To run the tests locally simply run::
5+
6+
python setup.py test
7+
8+
If you need to the development dependencies installed of you local IDE, you can run::
9+
10+
python setup.py develop
11+
12+
Documentation pull requests welcome. The Sphinx documentation can be compiled via::
13+
14+
python setup.py build_sphinx
15+
16+
Bug reports welcome, even more so if they include a correct patch. Much
17+
more so if you start your patch by adding a failing unit test, and correct
18+
the code until zero unit tests fail.
19+
20+
The list of supported Django and Python version can be found in the CI suite setup.
21+
Please make sure to verify that none of the linters or tests failed, before you submit
22+
a patch for review.

django_select2/forms.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,27 @@
2020
drop-in-replacement for Django's default
2121
select widgets.
2222
23-
2. **Heavy** --
23+
2(a). **Heavy** --
2424
They are suited for scenarios when the number of options
2525
are large and need complex queries (from maybe different
2626
sources) to get the options.
27+
2728
This dynamic fetching of options undoubtedly requires
2829
Ajax communication with the server. Django-Select2 includes
2930
a helper JS file which is included automatically,
3031
so you need not worry about writing any Ajax related JS code.
3132
Although on the server side you do need to create a view
3233
specifically to respond to the queries.
3334
34-
3. **Model** --
35+
2(b). **Model** --
3536
Model-widgets are a further specialized versions of Heavies.
3637
These do not require views to serve Ajax requests.
3738
When they are instantiated, they register themselves
3839
with one central view which handles Ajax requests for them.
3940
40-
Heavy widgets have the word 'Heavy' in their name.
41-
Light widgets are normally named, i.e. there is no
42-
'Light' word in their names.
41+
Heavy and Model widgets have respectively the word 'Heavy' and 'Model' in
42+
their name. Light widgets are normally named, i.e. there is no 'Light' word
43+
in their names.
4344
4445
.. inheritance-diagram:: django_select2.forms
4546
:parts: 1

docs/CONTRIBUTING.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. include:: ../CONTRIBUTING.rst

docs/django_select2.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ DjangoSelect2 handles the initialization of select2 fields automatically. Just i
4949
``{{ form.media.js }}`` in your template before the closing ``body`` tag. That's it!
5050

5151
If you insert forms after page load or if you want to handle the initialization
52-
yourself, DjangoSelect2 provides a jQuery plugin. It will handle both normal and
53-
heavy fields. Simply call ``djangoSelect2(options)`` on your select fields.::
52+
yourself, DjangoSelect2 provides a jQuery plugin, replacing and enhancing the Select2
53+
plugin. It will handle both normal and heavy fields. Simply call
54+
``djangoSelect2(options)`` on your select fields.::
5455

5556
$('.django-select2').djangoSelect2();
5657

@@ -59,6 +60,9 @@ You can pass see `Select2 options <https://select2.github.io/options.html>`_ if
5960

6061
$('.django-select2').djangoSelect2({placeholder: 'Select an option'});
6162

63+
Please replace all your ``.select2`` invocations with the here provided
64+
``.djangoSelect2``.
65+
6266
Security & Authentication
6367
-------------------------
6468

docs/get_started.rst

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1117
Installation
1218
------------
1319

@@ -17,11 +23,12 @@ Installation
1723

1824
2. 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(http://github.com/r'^select2/',%20include('django_select2.urls')),
30+
You can safely skip this one if you do not use any
31+
:class:`ModelWidgets <.django_select2.forms.ModelSelect2Mixin>`
2532

2633
Quick Start
2734
-----------
@@ -30,19 +37,22 @@ Here is a quick example to get you started:
3037

3138
0. 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

4757
2. Add the CSS to the ``head`` of your Django template::
4858

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Contents:
1515
get_started
1616
django_select2
1717
extra
18+
CONTRIBUTING
1819

1920
Indices and tables
2021
==================

0 commit comments

Comments
 (0)