plugin for django-selectable (to use with select2 UI)
Project description
This project is a kind of a plugin for django-selectable.
It provides widgets for use with a great JS library called select2 rather than jQuery UI. It also provides it’s own Lookup classes for better (IMO) serialization results and limiting results (on server side).
For now there’s only a basic single-valued autocomplete widget for usage on ForeignKey (or simply ModelChoiceField) fields.
Installation and usage
install django-selectable (you can ommit the part regarding jquery-ui)
add selectable_select2 to INSTALLED_APPS. So it look like this:
INSTALLED_APPS = ( ... 'selectable', 'selectable_select2', ... )
define your lookup class
in your forms you can use selectable_select2.widgets.AutoCompleteSelect2Widget like so:
from selectable_select2.widgets import AutoCompleteSelect2Widget from django import forms from myapp.models import MyModel # example model with a ForeignKey called ``myfk`` from myapp.lookups import MyModelLookup # the lookup defined in previous step class MyModelForm(forms.ModelForm): class Meta: model = MyModel widgets = { 'myfk' : AutoCompleteSelect2Widget(MyModelLookup, placeholder='select related item') }
Check the example project for more details.
TODO
check out TODO.rst
A note about version of select2.js used here
django-selectable-select2 comes bundled with “unstable” version of select2. This version is above commit 7baa3b9e9 (the unstable and unreleased 3.2 version) where you can provide your own function to escape the markup. If you want to use this version (e.g. on other select widgets in your project) do it like this:
<script src="{{ STATIC_URL }}selectable_select2/js/select2.min.js"></script>
See https://github.com/ivaynberg/select2/pull/355 for details.
Credits
A BIG THANK YOU goes to Igor Vaynberg (select2) and Mark Lavin (django-selectable) for their projects, their support and quick response time in resolving my issues.
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
Hashes for django-selectable-select2-0.1.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f977ed30295904e9412650c060b36f7752557d1eb35eca34283d7f658b1b0421 |
|
MD5 | f0b50ad45b206005a117b95f153a869b |
|
BLAKE2b-256 | 00b7d916a1761bae97273ca301769f3c12f19b5b2808118fde64e03e58a2817e |