-
We're using the HeavySelect2Widget widget in a django admin form to have a select field that queries data from another service (so
This seems to be a similar issue to applegrew#586 and django-cms/djangocms-link#180 but I'm not using Django CMS, just admin. I tried adding a custom widget that inherits from HeavySelect2Widget in order to set custom media, but I'm not sure what the class MyHeavySelect2Widget(HeavySelect2Widget):
class Media:
js = [
"admin/js/jquery.js",
]
class ContractInstanceForm(forms.ModelForm):
site_uid = forms.ChoiceField(
widget=MyHeavySelect2Widget(data_url="/contracts/site/search/")
) The resulting HTML looks like this <head>
<title>pactman | Add Trading Contract</title>
<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css">
<link rel="stylesheet" type="text/css" href="/static/admin/css/app.css">
<link rel="stylesheet" type="text/css" href="/static/admin/css/nav_sidebar.css">
<script src="/static/admin/js/nav_sidebar.js" defer=""></script>
<link href="//fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
<link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="icon" href="/static/images/cropped-favicon-43x43.png" sizes="32x32">
<link rel="icon" href="/static/images/cropped-favicon-300x300.png" sizes="192x192">
<link rel="stylesheet" type="text/css" href="/static/admin/css/forms.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="/pactman/jsi18n/"></script>
<link href="/static/admin/css/vendor/select2/select2.min.css" type="text/css" media="screen" rel="stylesheet">
<link href="/static/django_select2/django_select2.css" type="text/css" media="screen" rel="stylesheet">
<script src="/static/admin/js/vendor/jquery/jquery.js"></script>
<script src="/static/admin/js/vendor/select2/select2.full.min.js"></script>
<script src="/static/admin/js/calendar.js"></script>
<script src="/static/admin/js/jquery.init.js"></script>
<script src="/static/django_select2/django_select2.js"></script>
<script src="/static/admin/js/admin/DateTimeShortcuts.js"></script>
<script src="/static/admin/js/core.js"></script>
<script src="/static/admin/js/admin/RelatedObjectLookups.js"></script>
<script src="/static/admin/js/actions.js"></script>
<script src="/static/admin/js/urlify.js"></script>
<script src="/static/admin/js/prepopulate.js"></script>
<script src="/static/admin/js/vendor/xregexp/xregexp.js"></script>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" type="text/css" href="/static/admin/css/responsive.css">
<meta name="robots" content="NONE,NOARCHIVE">
</head> Changing the order to the script tags seems to fix the issue, but I don't how to make that permanent. I'm sorry about the mistaken early submission, this is my first issue I've raised. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @marshl, Thanks for reaching out. As it happens, I might have an idea where what's causing this error. Mainly because I implemented the change causing the issue in Django myself ;) Django 3.2 has native Select2 input support. I'd recommend switching to either Django's If run into any more problems, please let me know. Upgrading for such an old Django version is never a fun task. Might I recommend Adam's django-upgrade, to help you with some of that work? Cheers! |
Beta Was this translation helpful? Give feedback.
Hi @marshl,
Thanks for reaching out. As it happens, I might have an idea where what's causing this error. Mainly because I implemented the change causing the issue in Django myself ;)
Django 3.2 has native Select2 input support. I'd recommend switching to either Django's
autocomplete_fields
or for more advanced use cases to our Select2AdminMixin. Those will handle asset management properly for you.If run into any more problems, please let me know. Upgrading for such an old Django version is never a fun task. Might I recommend Adam's django-upgrade, to help you with some of that work?
Cheers!
Joe