{ "info": { "author": "Slawek Ehlert", "author_email": "slafs@op.pl", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Topic :: Utilities" ], "description": "django-selectable-select2\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. _issue in select2: https://github.com/ivaynberg/select2/issues/466\n\n.. warning::\n This is still a work in progress. Some backwards incompatible changes may happen between releases.\n\nThis project is a kind of a plugin for `django-selectable`_.\n\nIt provides widgets for use with a great JS library called `select2`_ rather than jQuery UI.\n\nFor now there's only a basic single-valued autocomplete widget for usage on ForeignKey (or simply ModelChoiceField) fields.\n\nInstallation\n=============\n\n\n* install `django-selectable`_ (you can ommit the part regarding jquery-ui)\n\n* install `django-selectable-select2` like so::\n\n pip install django-selectable-select2\n\n* add `selectable_select2` to `INSTALLED_APPS`. So it look like this::\n\n INSTALLED_APPS = (\n ...\n 'selectable',\n 'selectable_select2',\n ...\n )\n\n* add/change a setting ``SELECTABLE_ESCAPED_KEYS`` like this::\n\n SELECTABLE_ESCAPED_KEYS = ('label', 'value')\n\n\nYou can also get all the static files dependencies like this::\n\n pip install django-staticfiles-jquery\n pip install django-staticfiles-select2\n\nand add them to ``INSTALLED_APPS``::\n\n INSTALLED_APPS = (\n ...\n 'jquery',\n 'staticfiles_select2',\n ...\n )\n\n\n\nUsage\n============\n\n* define your `lookup class`_\n\n* in your forms you can use ``selectable_select2.widgets.AutoCompleteSelect2Widget`` like so::\n\n from selectable_select2.widgets import AutoCompleteSelect2Widget\n from django import forms\n\n from myapp.models import MyModel # example model with a ForeignKey called ``myfk``\n from myapp.lookups import MyModelLookup # the lookup defined in previous step\n\n class MyModelForm(forms.ModelForm):\n\n class Meta:\n model = MyModel\n widgets = {\n 'myfk' : AutoCompleteSelect2Widget(MyModelLookup, placeholder='select related item')\n }\n\nHow to include static assets?\n----------------------------------\n\n.. warning::\n\n As of version 0.4.0 `django-selectable-select2` doesn't include any static files dependencies for select2 itself.\n Use `django-staticfiles-select2` and/or `django-staticfiles-jquery` if you don't have them already in your project.\n\nYou can mannually include those assets (assuming you're using django-staticfiles). Like so::\n\n \n
\n \n \n\n \n \n\n \n \n \n \n \n\nChained selects\n----------------\n\nThere is a way to do chained selects in `django-selectable`.\nCheck out the `docs about chained selects`_ to correctly prepare your lookup classes\nfor this use case (you can skip the javascript part).\nDjango-selectable-select2 provides a helper class to declare dependencies of your chained selects\non your form.\n\nSo given the lookup, from the above link and assuming that MyModel has ForeignKeys\nfor city and state, your form class can inherit from ``Select2DependencyModelForm``\nand define ``select2_deps`` attribute like this::\n\n from selectable_select2.forms import Select2DependencyModelForm\n from django import forms\n from selectable_select2.widgets import AutoCompleteSelect2Widget\n\n class ChainedForm(Select2DependencyModelForm):\n\n select2_deps = (\n ('city', { 'parents' : ['state'] }),\n )\n\n class Meta:\n model = MyModel\n widgets = {\n 'city' : AutoCompleteSelect2Widget(CityLookup, placeholder='select city')\n }\n\nThere is also ``Select2DependencyForm`` which is suitable for non-model based forms.\n\n.. note::\n Both ``Select2DependencyModelForm`` and ``Select2DependencyForm``\n in ``selectable_select2.forms`` module inherit from a general class called\n ``Select2DependencyFormMixin`` which defines one method called ``apply_select2_deps``.\n Don't hesitate to browse the source of those classes.\n\n\n``select2_deps`` is a tuple of two-tuples in form `('