Skip to content
Merged
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ stages:

jobs:
include:
- python: "3.5"
- python: "3.7"
env: TOXENV=docs
addons:
apt:
Expand Down
22 changes: 22 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Contributing
============

This package uses the pyTest test runner. To run the tests locally simply run::

python setup.py test

If you need to the development dependencies installed of you local IDE, you can run::

python setup.py develop

Documentation pull requests welcome. The Sphinx documentation can be compiled via::

python setup.py build_sphinx

Bug reports welcome, even more so if they include a correct patch. Much
more so if you start your patch by adding a failing unit test, and correct
the code until zero unit tests fail.

The list of supported Django and Python version can be found in the CI suite setup.
Please make sure to verify that none of the linters or tests failed, before you submit
a patch for review.
11 changes: 6 additions & 5 deletions django_select2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,27 @@
drop-in-replacement for Django's default
select widgets.

2. **Heavy** --
2(a). **Heavy** --
They are suited for scenarios when the number of options
are large and need complex queries (from maybe different
sources) to get the options.

This dynamic fetching of options undoubtedly requires
Ajax communication with the server. Django-Select2 includes
a helper JS file which is included automatically,
so you need not worry about writing any Ajax related JS code.
Although on the server side you do need to create a view
specifically to respond to the queries.

3. **Model** --
2(b). **Model** --
Model-widgets are a further specialized versions of Heavies.
These do not require views to serve Ajax requests.
When they are instantiated, they register themselves
with one central view which handles Ajax requests for them.

Heavy widgets have the word 'Heavy' in their name.
Light widgets are normally named, i.e. there is no
'Light' word in their names.
Heavy and Model widgets have respectively the word 'Heavy' and 'Model' in
their name. Light widgets are normally named, i.e. there is no 'Light' word
in their names.

.. inheritance-diagram:: django_select2.forms
:parts: 1
Expand Down
1 change: 1 addition & 0 deletions docs/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../CONTRIBUTING.rst
8 changes: 6 additions & 2 deletions docs/django_select2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ DjangoSelect2 handles the initialization of select2 fields automatically. Just i
``{{ form.media.js }}`` in your template before the closing ``body`` tag. That's it!

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

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

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

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

Please replace all your ``.select2`` invocations with the here provided
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Please replace all your ``.select2`` invocations with the here provided
Please replace your ``.select2`` invocations with the here provided

``.djangoSelect2``.

Security & Authentication
-------------------------

Expand Down
36 changes: 23 additions & 13 deletions docs/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Overview
.. automodule:: django_select2
:members:

Assumptions
-----------

* You have a running Django up and running.
* You have form fully working without Django-Select2.

Installation
------------

Expand All @@ -17,11 +23,12 @@ Installation

2. Add ``django_select2`` to your ``INSTALLED_APPS`` in your project settings.

3. Add ``django_select`` to your ``urlconf``::

3. Add ``django_select`` to your ``urlconf`` **if** you use any
:class:`ModelWidgets <.django_select2.forms.ModelSelect2Mixin>`::
path('select2/', include('django_select2.urls')),

url(r'^select2/', include('django_select2.urls')),
You can safely skip this one if you do not use any
:class:`ModelWidgets <.django_select2.forms.ModelSelect2Mixin>`

Quick Start
-----------
Expand All @@ -30,19 +37,22 @@ 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::
1. Replace native Django forms widgets with one of the several ``django_select2.form`` widgets.
Start by importing them into your ``forms.py``, right next to Django own ones::

class MyForm(forms.Form):
things = ModelMultipleChoiceField(queryset=Thing.objects.all())
from django import forms
from django_select2 import forms as s2forms
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call to include the imports. I always forget 👍


with::
Then let's assume you have a model with a choice, a :class:`.ForeignKey`, and a
:class:`.ManyToManyField`, you would add this information to your Form Meta
class::

from django_select2.forms import Select2MultipleWidget

class MyForm(forms.Form):
things = ModelMultipleChoiceField(queryset=Thing.objects.all(), widget=Select2MultipleWidget)
widgets = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include the entire code example, otherwise people will be confused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't written it yet. I'll review the PR in its entirety, and come back to you soon (36h).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

36h went by, and I'm still busy on the project I'm working at. (mfrasca/ghini)
sooner or later, from that project, I will again need to dive into djangoSelect2, and I will again read the docs and amend the docs where what I will be reading doesn't make sense to me.
in particular, I will need the Multiple select widget, which I've not yet used.

'category': s2forms.Select2Widget,
'author': s2forms.ModelSelect2Widget(model=auth.get_user_model(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did not import auth, I would also suggest to import get_user_model directly instead, since you don't use anything else from the auth module.

search_fields=['first_name__istartswith', 'last_name__icontains']),
'attending': s2forms.ModelSelect2MultipleWidget …
}

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

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Contents:
get_started
django_select2
extra
CONTRIBUTING

Indices and tables
==================
Expand Down