How create Multiple Select Box in Django?

早过忘川 提交于 2019-12-04 14:19:14

Here's an idea. I think you need to initialize it yourself with the jquery plugin provided by Django-Select2. Following the Django-Select2 docs and the Select2 docs, you might need to do the following:

$('.django-select2').djangoSelect2({multiple: true});

Finally I found solution. My problem was that I load my form by AJAX. For thats why {{ product_form.media.js }} and {{ product_form.media.css }} didnt work.

Instead of {{ product_form.media.js }} and {{ product_form.media.css }} I use this in my template:

<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css">
<script src="{% static 'django_select2/django_select2.js' %}"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!