Django select2 theme for select input widgets.
Project description
This is simple django application that brings select2 widget to select inputs in admin.
Install
install this package as usual, using python setup.py install, pip install django-easy-select2 or download sources and install to your python path.
add easy_select2 to INSTALLED_APPS in your settings.py
Use python manage.py collectstatic or manually copy easy_select2’s static directory to your project’s static directory (if you serve your static with nginx, for example).
Modify your admin.py.
Check out admin in browser.
Configuration
django-easy-select2 bundles jquery and select2 static files. You can use them, or specify your own files to include in widget.
To use bundled static, just install an application.
To use your custom static files, you can specify next settings in your settings.py:
SELECT2_JS - path to select2.js file. Specify path without static directory, because full URL will be interpolated using static function from staticfiles application. Default is: easy_select2/vendor/select2/select2.min.js
SELECT2_CSS - path to select2.css file. Default is: easy_select2/vendor/select2/select2.min.css
SELECT2_USE_BUNDLED_JQUERY - default True. Set to False if your already have included custom jQuery in your admin side.
Usage
There are Select2 widget class. You can use it on any form field, as usual django widget:
class Form(forms.Form): field = forms.ModelChoiceField(queryset=qs, widget=Select2())
If you want to use it on all form fields automatically, without specifying easy field, you can create your ModelForm class with Meta class constructed by custom Meta factory:
from easy_select2 import select2_meta_factory class SomeModelForm(forms.ModelForm): Meta = select2_meta_factory(SomeModel)
select2_meta_factory is a simple factory, that produces a class Meta with model attribute set to specified model and widgets attribute set to dictionary, containing all selectable fields on model.
If you are lazy, you can use ModelForm factory to build ready-to-use ModelForm for model:
from easy_select2 import select2_modelform MyModelForm = select2_modelform(MyModel)
MyModelForm is an instance of ModelForm with model attribute set to MyModel, and appropriate Meta class.
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
File details
Details for the file django-easy-select2-1.0.2.tar.gz
.
File metadata
- Download URL: django-easy-select2-1.0.2.tar.gz
- Upload date:
- Size: 149.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f2ab139aee0ca56f281e9e51c2bdbe4f7194c8b74db6aec5039fede7cf22e4f |
|
MD5 | 96a443040030b4aeb8ced2593348e662 |
|
BLAKE2b-256 | 7d7ae83fef2d0b667e6538c5857a5abcde5369892601eb0ac6de6e4218f81d3c |