Symptoms: While using AutoModelSelect2Field in admin site, I noticed that css files are rendered only at the first request to the add or edit forms, after that the widget is rendered but without loading any css files from get_select2_css_libs. Solution: I changed assets loading from Assets as a static definition to Media as a dynamic property as described at Django docs: https://docs.djangoproject.com/en/1.8/topics/forms/media/#media-as-a-dynamic-property Closed #179 Squashed commit of the following: commit f925ed4a118687b82b6f61d21a9104ccf00859c8 Author: Razi Alsayyed <razi.sayed@gmail.com> Date: Fri Jun 19 01:39:47 2015 +0300 remove trailing whitespace from docstrings commit b3f6553e422e19c8e065e026511c4ffd91ffee42 Author: Razi Alsayyed <razi.sayed@gmail.com> Date: Fri Jun 19 01:35:15 2015 +0300 Remove blank lines from docstrings commit 4490b78572a25069472933c88ebee48445b59972 Author: Razi Alsayyed <razi.sayed@gmail.com> Date: Fri Jun 19 01:19:38 2015 +0300 construct Media the right way Remove code that access private attributes of Media class. commit 6697cd734daca62ff099be73d0685ce6af32e53d Author: Razi Alsayyed <razi.sayed@gmail.com> Date: Tue Jun 16 00:11:29 2015 +0300 fix change _media to _get_media I hope it is the final commit :) commit 59bda01aed44e5658825a1bfe37ad09c5760a3ad Author: Razi Alsayyed <razi.sayed@gmail.com> Date: Tue Jun 16 00:09:35 2015 +0300 get_select2_heavy_js_libs change get_select2_js_libs to get_select2_heavy_js_libs commit 993e201355c9d5a6012e6f67cfa64462576c2570 Author: Razi Alsayyed <razi.sayed@gmail.com> Date: Tue Jun 16 00:07:57 2015 +0300 fix fix commit f66e5f40b9f4df295bc5aaa7f2aafe588b2c41bb Author: Razi Alsayyed <razi.sayed@gmail.com> Date: Mon Jun 15 23:55:53 2015 +0300 fix fix commit d33d90278345bc32e80e20bdf782fd9ac5eb1800 Author: Razi Alsayyed <razi.sayed@gmail.com> Date: Mon Jun 15 23:47:25 2015 +0300 fix fix commit f6d956149d2e99ee504c7b2c110f959f7472a181 Author: Razi Alsayyed <razi.sayed@gmail.com> Date: Mon Jun 15 23:45:09 2015 +0300 fix fix commit 6d737a78cc07507c5b9b91736f6662b5f6f31c57 Author: Razi Alsayyed <razi.sayed@gmail.com> Date: Mon Jun 15 23:40:01 2015 +0300 global name 'Media' is not defined global name 'Media' is not defined commit 661a817b092dc72bfa8df1a5458d474599c0a50e Author: Razi Alsayyed <razi.sayed@gmail.com> Date: Mon Jun 15 23:27:27 2015 +0300 Media as a dynamic property **Symptoms:** While using AutoModelSelect2Field in admin site, I noticed that css files are rendered only at the first request to the add or edit forms, after that the widget is rendered but without loading any css files from get_select2_css_libs. **Solution:** I changed assets loading from [Assets as a static definition](https://docs.djangoproject.com/en/1.8/topics/forms/media/#media-as-a-dynamic-property) to [Media as a dynamic property](https://docs.djangoproject.com/en/1.8/topics/forms/media/#media-as-a-dynamic-property) as described at Django docs. |
||
|---|---|---|
| django_select2 | ||
| docs | ||
| testapp | ||
| tests | ||
| .gitignore | ||
| .travis.yml | ||
| Internal_Notes.md | ||
| LICENSE.txt | ||
| MANIFEST.in | ||
| pytest.ini | ||
| README | ||
| README.md | ||
| requirements_dev.txt | ||
| runtests.py | ||
| setup.py | ||
| UK_Advanced_Cryptics_Dictionary_Licensing_Information.txt | ||
Django-Select2 
This is a Django integration of Select2.
The app includes Select2 driven Django Widgets and Form Fields.
Installation
-
Install
django_select2pip install django_select2 -
Add
django_select2to yourINSTALLED_APPSin your project settings. -
When deploying on production server, run :-
python manage.py collectstatic -
Add
django_selectto your urlconf if you use any 'Auto' fields.url(r'^select2/', include('django_select2.urls')),
Documentation
Documentation available at http://django-select2.readthedocs.org/.
More details
More details can be found on my blog at - http://blog.applegrew.com/2012/08/django-select2/.
External Dependencies
- Django - This is obvious.
- jQuery - This is not included in the package since it is expected that in most scenarios this would already be available.
- Memcached (python-memcached) - If you plan on running multiple python processes with
GENERATE_RANDOM_SELECT2_IDenabled, then you need to turn onENABLE_SELECT2_MULTI_PROCESS_SUPPORT. In that mode it is highly recommended that you use Memcached, to minimize DB hits.
Example Application
Please see testapp application. This application is used to manually test the functionalities of this package. This also serves as a good example.
You need only Django 1.4 or above to run that. It might run on older versions but that is not tested.
Special Thanks
- Samuel Goldszmidt (@ouhouhsami) for reporting many fundamental issues with the code, because of which versions 2.0 and 2.0.1 were released.
Official Contributors
- Johannes Hoppe (@codingjoe)
Changelog Summary
v4.3.1
- Build failure fix.
v4.3.0
- Now the package supports both Python2 and Python3.
- Django 1.8 support added.
- Many bug fixes.
v4.2.2
v4.2.1
- Finally fixed performance issue#54 (and issue#41) in widgets when backing field is based on models and the field has an initial value.
v4.2.0
- Updated Select2 to version 3.4.2. Please note, that if you need any of the Select2 locale files, then you need to download them yourself from http://ivaynberg.github.com/select2/ and add to your project.
- Tagging support added. See Field API reference in documentation.
v4.1.0
- Updated Select2 to version 3.4.1. Please note, that if you need any of the Select2 locale files, then you need to download them yourself from http://ivaynberg.github.com/select2/ and add to your project.
- Address isssue#36 - Fix importerror under django1.6.
- Fixed the way
setup.pyhandles Unicode files while minifying them during package build. - Address isssue#39 - MultipleSelect2HiddenInput.render() should use mark_safe().
- Address isssue#45 - MultipleSelect2HiddenInput returns bad has_changed value.
v4.0.0
- Main version number bumped to bring your attention to the fact that the default Id generation scheme has now changed. Now Django Select2 will use hashed paths of fields to generate their Ids. The old scheme of generating random Ids are still there. You can enable that by setting
GENERATE_RANDOM_SELECT2_IDtoTrue.
v3.3.1
- Addressed issue#30.
- Merged pull request#31.
- Added
lightparameter toimport_django_select2_js,import_django_select2_cssandimport_django_select2_js_csstemplate tags. Please see doc's "Getting Started", for more details.
v3.3.0
- Updated Select2 to version 3.3.1.
- Added multi-process support. (Issue#28).
- Addressed issue#26.
- Addressed issue#24.
- Addressed issue#23.
- Addressed some typos.
v3.2.0
- Fixed issue#20. Infact while fixing that I realised that heavy components do not need the help of cookies, infact due to a logic error in previous code the cookies were not being used anyway. Now Django Select2 does not use cookies etc.
- Few more bugs fixed in
heav_data.js. - Now production code will use minimized versions of js and css files.
- Codes added in
setup.pyto automate the task of minimizing js and css files, using a web service.
v3.1.5
- Merged pull request (issue#17). Which allows the user to pass some extra data to Select2 clients-side component.
- Updated License. The previous one was inadequently worded. Now this project use Apache 2.0 license.
v3.1.4
- Manually merged changes from pull request (issue#16).
- Django Select2 widgets now allow passing of any Select2 Js options. Previously it used to allow only white-listed options. Now it will block only black-listed options. For example, Light Select2 widgets won't allow you to set
multipleoption, since it is an error to set them when Select2 Js is bound to<select>fields.
v3.1.3
v3.1.2
- Fixed issue#7.
v3.1.1
- Bumping up minor version since Select2 JS has been updated to version 3.2. It seems Select2 JS now includes new higher resolution icons for Retina displays.
- Fixed an issue in
setup.pybecause of whichtemplatetagsdirectory was not included in last PIP releases' tar file.
v3.0.2
- Added
AUTO_RENDER_SELECT2_STATICSsettings. This, when specified and set toFalseinsettings.pythen Django_Select2 widgets won't automatically include the required scripts and stylesheets. When this setting isTrue(default) then every Select2 field on the page will output<script>and<link>tags to include the required JS and CSS files. This is convinient but will output the same JS and CSS files multiple times if there are more than one Select2 fields on the page. - Added
django_select2_tagstemplate tags to manually include the required JS and CSS files, whenAUTO_RENDER_SELECT2_STATICSis turned off.
v3.0.1
- Revised the design of heavy fields. The previous design didn't quite make it easy to back heavy fields by big data sources. See
fields.HeavyChoiceFieldclass and its methods' docs for more info. - Updated docs.
- Some more fixes for issue#4.
- Updated Select2 JS to version 3.1.
v3.0
- Added docs.
- Some bug fixes. See issue#4.
widgets.Select2Mixin.__init__now acceptsselect2_optionskwarg to override itsoptionssettings. Previouslyattrswere being used for this too. This means backward compatibility has been broken here.attrswill no longer overrideoptionsvalues. The major release version has been changed to 3, because of this backward incompatible change.
v2.0.1
- Auto id registration fixes.
v2.0
-
Mostly major bug fixes in code and design. The changes were many, raising the possibility of backward incompatibility. However, the backward incompatibility would be subtle.
-
Auto fields (sub-classes of AutoViewFieldMixin) now accepts
auto_idparameter. This can be used to provide custom id for the field. The default is 'module.field_class_name'. Ideally only the first instance of an auto field is registered. This parameter can be used to force registration of additional instances by passing a unique value.
License
Copyright 2012 Nirupam Biswas
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.