From 50c488c0125f571f87e30e480e21446338a1b3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marduk=20Bola=C3=B1os?= Date: Fri, 9 Aug 2024 18:02:58 +0200 Subject: [PATCH] Fix #292 -- Change admin widgets' JS media ordering (#295) Select2Mixin now loads admin/js/jquery.init.js, just like the AutocompleteMixin of Django Admin. --------- Co-authored-by: Johannes Maron --- django_select2/forms.py | 6 +++++- tests/test_forms.py | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/django_select2/forms.py b/django_select2/forms.py index 69b1ee3c..85f84672 100644 --- a/django_select2/forms.py +++ b/django_select2/forms.py @@ -169,8 +169,12 @@ class Select2AdminMixin: def media(self): css = {**AutocompleteMixin(None, None).media._css} css["screen"].append("django_select2/django_select2.css") + js = [*Select2Mixin().media._js] + js.insert( + js.index("django_select2/django_select2.js"), "admin/js/jquery.init.js" + ) return forms.Media( - js=Select2Mixin().media._js, + js=js, css=css, ) diff --git a/tests/test_forms.py b/tests/test_forms.py index ddb0f328..71b0b042 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -188,6 +188,7 @@ def test_media(self): assert tuple(Select2AdminMixin().media._js) == ( "admin/js/vendor/select2/select2.full.min.js", "admin/js/vendor/select2/i18n/en.js", + "admin/js/jquery.init.js", "django_select2/django_select2.js", )