A Django application to provide AJAX autocomplete with Select2.
Project description
Light integration glue between Django and Select2.
This project is inspired by Django-Select2 and django-select2light.
Django-select2-rocks is distributed under the BSD 2-clause license.
Installation
pip install django_select2_rocks
add select2rocks to your INSTALL_APPS
python manage.py collectstatic will install Django Select2 Rocks JS.
Include jQuery (1.7+), Select2 JS/CSS (not provided, tested with v3.4.5) and select2rocks/select2rocks.js in your templates.
Now, you can use Select2ModelChoiceField fields in your forms.
Design
Django-select2-rocks provides widgets to render and initialize Select2 inputs.
The widget rendering is based on Django with a further step which adds a JS initialization for each input (on DOM ready). When a character is typed in the input field, an AJAX request is sent to the URL associated to the field.
The widget API is designed to allow you to pass any arguments you want to Select2 JS code (eg. allowClear option).
You can use various JSON views to answer to Select2 AJAX queries, and so to adjust search terms or the format of the results, it’s possible to extend the default django-select2-rocks backend (see select2rocks-backends.js in testproj for an example).
Example
The testproj project contains examples with a simple JSON view, a Tastypie and a Django REST framework view.
import select2rocks
class BeachForm(forms.Form):
beach = select2rocks.Select2ModelChoiceField(
queryset=Beach.objects.all(),
widget=select2rocks.AjaxSelect2Widget(url_name='json_beaches'))
Get the Code
Django-select2-rocks is developed on GitHub:
You can either clone the public repository:
$ git clone git://github.com/polyconseil/django-select2-rocks.git
Once you have a copy of the source, you can install it with:
$ python setup.py install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-select2-rocks-0.5.0.tar.gz
.
File metadata
- Download URL: django-select2-rocks-0.5.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58a35b993f6150f6126f5c3cf2c72210bdaff97f396a46956d149a4fa6287061 |
|
MD5 | fcac75a428517c89e086ce8f2649dec8 |
|
BLAKE2b-256 | fdb11260e8564eaf58d45744cbc53473590387e93a5b15a9177da438558ba65c |
File details
Details for the file django_select2_rocks-0.5.0-py2-none-any.whl
.
File metadata
- Download URL: django_select2_rocks-0.5.0-py2-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be8d8add3bb1a4438c06f5229f26a68f9b16a479c74469a4f3c5b4da55151f9a |
|
MD5 | 875cf2c7b21b78ff08082c2141cd9a87 |
|
BLAKE2b-256 | b45c788183fbe3ac7fe987b3ae226923f66e376da1973f9e481233c25c429264 |