├── .github └── workflows │ └── test.yml ├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.rst ├── select2 ├── __init__.py ├── fields.py ├── forms.py ├── models │ ├── __init__.py │ ├── base.py │ └── descriptors.py ├── static │ └── select2 │ │ ├── css │ │ ├── select2-spinner.gif │ │ ├── select2.css │ │ ├── select2.png │ │ └── select2x2.png │ │ ├── js │ │ ├── jquery-1.7.2.js │ │ ├── select2.jquery_ready.js │ │ ├── select2.jquery_ui_sortable.js │ │ ├── select2.js │ │ └── select2.min.js │ │ └── select2 │ │ ├── LICENSE │ │ ├── README.md │ │ ├── component.json │ │ ├── release.sh │ │ ├── select2-spinner.gif │ │ ├── select2.css │ │ ├── select2.js │ │ ├── select2.png │ │ └── select2x2.png ├── urls.py ├── utils.py ├── views.py └── widgets.py ├── setup.cfg ├── setup.py ├── tests ├── __init__.py ├── admin.py ├── manage.py ├── models.py ├── settings.py ├── test_admin.py └── urls.py └── tox.ini /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: push 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | python-version: [3.7, 3.8, 3.9] 11 | 12 | steps: 13 | - uses: actions/checkout@v3 14 | 15 | - name: Set up Python ${{ matrix.python-version }} 16 | uses: actions/setup-python@v4 17 | with: 18 | python-version: ${{ matrix.python-version }} 19 | 20 | - name: Setup chromedriver 21 | uses: nanasess/setup-chromedriver@v1.0.5 22 | 23 | - name: Install dependencies 24 | run: | 25 | python -m pip install --upgrade pip 26 | pip install tox tox-gh-actions 27 | 28 | - name: Test with tox 29 | run: | 30 | tox -- -v --selenosis-driver=chrome-headless || \ 31 | tox -- -v --selenosis-driver=chrome-headless || \ 32 | tox -- -v --selenosis-driver=chrome-headless 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /dist 3 | /*.egg-info 4 | *.pyc 5 | *.log 6 | *.egg 7 | *.db 8 | *.pid 9 | pip-log.txt 10 | .DS_Store 11 | *swp 12 | ghostdriver.log 13 | .tox 14 | venv/ 15 | .python-version 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This software is published under the BSD 2-Clause License as listed below. 2 | http://www.opensource.org/licenses/bsd-license.php 3 | 4 | Copyright (c) 2017, Atlantic Media 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | recursive-include select2/static * 4 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | django-select2-forms 2 | #################### 3 | 4 | .. image:: https://travis-ci.org/theatlantic/django-select2-forms.svg?branch=master 5 | :target: https://travis-ci.org/theatlantic/django-select2-forms 6 | 7 | **django-select2-forms** is a project that makes available Django form 8 | fields that use the `Select2 javascript 9 | plugin `_. It was created by 10 | developers at `The Atlantic `_. 11 | 12 | .. contents:: Table of Contents: 13 | 14 | Support 15 | ======= 16 | 17 | Being that Django added select2 support in 2.0, we will support up to that version 18 | for compatibility purposes. 19 | 20 | * ~=v3.0: Python >=3.7,<3.9 | Django 2.2,3.1,3.2 (current release) 21 | 22 | Local Development & Testing 23 | =========================== 24 | 25 | The following steps should only need to be done once when you first begin: 26 | 27 | Install ``pyenv`` 28 | ----------------- 29 | 30 | These instructions assume that you have `Homebrew `_ installed, 31 | but not ``pyenv``. 32 | 33 | .. code:: bash 34 | 35 | brew install pyenv 36 | touch ~/.bash_profile 37 | 38 | Add the following line to your ``~/bash_profile`` or ``.zshrc``:: 39 | 40 | eval "$(pyenv init -)" 41 | 42 | Reload your shell: 43 | 44 | .. code:: bash 45 | 46 | . ~/.bash_profile 47 | 48 | or 49 | 50 | .. code:: bash 51 | 52 | . ~/.zshrc 53 | 54 | Python Repository Setup 55 | ----------------------- 56 | 57 | First, clone the repository and prep your Python environment: 58 | 59 | .. code:: bash 60 | 61 | git clone https://github.com/theatlantic/django-select2-forms.git 62 | pyenv install 3.7.2 63 | pyenv install 3.8.0 64 | pyenv install 3.9.0 65 | pyenv local 3.7.2 3.8.0 3.9.0 66 | python -V 67 | 68 | The output of the previous command should be ``Python 3.7.2``. 69 | 70 | Finally: 71 | 72 | .. code:: bash 73 | 74 | python -m venv venv 75 | 76 | Activate Your Environment 77 | ------------------------- 78 | 79 | From the base directory: 80 | 81 | .. code:: bash 82 | 83 | deactivate # ignore: -bash: deactivate: command not found 84 | . venv/bin/activate 85 | pip install -U tox 86 | 87 | Running tests 88 | ------------- 89 | 90 | If you have not already done so, set up your environment by chromedriver: 91 | 92 | .. code:: bash 93 | 94 | brew install --cask chromedriver 95 | 96 | Run all tests: 97 | 98 | .. code:: bash 99 | 100 | tox -- --selenosis-driver=chrome-headless 101 | 102 | Show all available ``tox`` commands: 103 | 104 | .. code:: bash 105 | 106 | tox -av 107 | 108 | Run only a specific environment: 109 | 110 | .. code:: bash 111 | 112 | tox -e -- --selenosis-driver=chrome-headless # example: tox -e py37-django22 113 | 114 | Only run a specific test: 115 | 116 | .. code:: bash 117 | 118 | tox -- pytest -k test_something --selenosis-driver=chrome-headless 119 | 120 | Run an arbitrary command in a specific environment: 121 | 122 | .. code:: bash 123 | 124 | tox -e py37-django22 -- python # runs the Python REPL in that environment 125 | 126 | Setup a development environment: 127 | 128 | .. code:: bash 129 | 130 | tox -e --develop -r 131 | . .tox//bin/activate 132 | 133 | Installation 134 | ============ 135 | 136 | The recommended way to install is with pip:: 137 | 138 | pip install django-select2-forms 139 | 140 | or, to install with pip from source:: 141 | 142 | pip install -e git+git://github.com/theatlantic/django-select2-forms.git#egg=django-select2-forms 143 | 144 | If the source is already checked out, use setuptools:: 145 | 146 | python setup.py develop 147 | 148 | Configuration 149 | ============= 150 | 151 | ``django-select2-forms`` serves static assets using 152 | `django.contrib.staticfiles `_, 153 | and so requires that ``"select2"`` be added to your settings' 154 | ``INSTALLED_APPS``: 155 | 156 | .. code-block:: python 157 | 158 | INSTALLED_APPS = ( 159 | # ... 160 | 'select2', 161 | ) 162 | 163 | To use django-select2-forms' ajax support, ``'select2.urls'`` must be 164 | included in your urls.py ``urlpatterns``: 165 | 166 | .. code-block:: python 167 | 168 | urlpatterns = patterns('', 169 | # ... 170 | url(r'^select2/', include('select2.urls')), 171 | ) 172 | 173 | Usage 174 | ===== 175 | 176 | The simplest way to use ``django-select2-forms`` is to use 177 | ``select2.fields.ForeignKey`` and ``select2.fields.ManyToManyField`` in 178 | place of ``django.db.models.ForeignKey`` and 179 | ``django.db.models.ManyToManyField``, respectively. These fields extend 180 | their django equivalents and take the same arguments, along with extra 181 | optional keyword arguments. 182 | 183 | select2.fields.ForeignKey examples 184 | ---------------------------------- 185 | 186 | In the following two examples, an "entry" is associated with only one 187 | author. The example below does not use ajax, but instead performs 188 | autocomplete filtering on the client-side using the ``