Skip to content

Commit

Permalink
Add list support for static asset settings (#189)
Browse files Browse the repository at this point in the history

Co-authored-by: Johannes Maron <[email protected]>
  • Loading branch information
pickfire and codingjoe authored Feb 8, 2023
1 parent 3e1527f commit 38ce1d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions django_select2/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,32 @@ class Select2Conf(AppConf):
It has set `select2_` as a default value, which you can change if needed.
"""

JS = "admin/js/vendor/select2/select2.full.min.js"
JS = ["admin/js/vendor/select2/select2.full.min.js"]
"""
The URI for the Select2 JS file. By default this points to version shipped with Django.
If you want to select the version of the JS library used, or want to serve it from
the local 'static' resources, add a line to your settings.py like so::
SELECT2_JS = 'assets/js/select2.min.js'
SELECT2_JS = ['assets/js/select2.min.js']
If you provide your own JS and would not like Django-Select2 to load any, change
this setting to a blank string like so::
SELECT2_JS = ''
SELECT2_JS = []
.. tip:: Change this setting to a local asset in your development environment to
develop without an Internet connection.
"""

CSS = "admin/css/vendor/select2/select2.min.css"
CSS = ["admin/css/vendor/select2/select2.min.css"]
"""
The URI for the Select2 CSS file. By default this points to version shipped with Django.
If you want to select the version of the library used, or want to serve it from
the local 'static' resources, add a line to your settings.py like so::
SELECT2_CSS = 'assets/css/select2.css'
SELECT2_CSS = ['assets/css/select2.css']
If you want to add more css (usually used in select2 themes), add a line
in settings.py like this::
Expand All @@ -93,7 +93,7 @@ class Select2Conf(AppConf):
If you provide your own CSS and would not like Django-Select2 to load any, change
this setting to a blank string like so::
SELECT2_CSS = ''
SELECT2_CSS = []
.. tip:: Change this setting to a local asset in your development environment to
develop without an Internet connection.
Expand Down
4 changes: 3 additions & 1 deletion django_select2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ def media(self):
.. Note:: For more information visit
https://docs.djangoproject.com/en/stable/topics/forms/media/#media-as-a-dynamic-property
"""
select2_js = [settings.SELECT2_JS] if settings.SELECT2_JS else []
select2_js = settings.SELECT2_JS if settings.SELECT2_JS else []
select2_css = settings.SELECT2_CSS if settings.SELECT2_CSS else []

if isinstance(select2_js, str):
select2_js = [select2_js]
if isinstance(select2_css, str):
select2_css = [select2_css]

Expand Down

0 comments on commit 38ce1d6

Please sign in to comment.