AutoModelSelect2Field not working with django-select2

I am using select2 for my dropdown menus. I have a dropdown that contains about 18,000 entries, so I want to use HeavySelect2Widget for it. I get an error
Reverse 'django_select2_central_json' with arguments () and keyword arguments '{}' not found
Any idea what the problem is. The class name and field used are as follows.


class EmployeeChoices(AutoModelSelect2Field): fname = FirstName() queryset = [(1,'value 1')]#fname.getAllNames() search_fields = ['name__icontains',] 

 field_name = EmployeeChoices( required=False, widget=AutoHeavySelect2Widget( select2_options={ 'placeholder': u"Select a choice" } ), label='' ) 
+4
source share
3 answers

You must include the django_select2 urls in your urls.py :

 from django.conf.urls import patterns, url, include urlpatterns = patterns('', url(...), url(r'^someurlprefix/', include('django_select2.urls')), url(...), ) 

r'^someprefix/' is a regex expression, and url_patterns uses this regex expression to match URLs to view functions. If you specify a prefix here (it could even be r'' , something that I personally use), the Django reverse function will automatically provide the correct URL to go to the django_select2_central_json .

Also check out the Django URL Manager documentation.

+7
source

I managed to add the following line to the directory: /static/suit/js/suit.js

Add

 (function ($) { Suit.after_inline.register('init_select2', function(inline_prefix, row){ $(row).find('select').select2(); }); 
0
source

add django_select2 urls in urls.py project settings:

url(r'^select2/', include('django_select2.urls')),

0
source

Source: https://habr.com/ru/post/1494111/


All Articles