Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoModelSelect2Field not working using django-select2

I am using select2 for my dropdowns. I have dropdown that has some 18000 entries , so I want to use HeavySelect2Widget for it. I getting an error
Reverse of 'django_select2_central_json' with arguments () and keyword arguments '{}' not found
Any idea what's the problem.The class and field name used is given below


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=''
)
like image 318
Waheed Khan Avatar asked Mar 22 '23 23:03

Waheed Khan


1 Answers

You have to 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 the url_patterns uses this regex expression to map urls to view functions. If you specify the prefix here (it can even be r'', that's what I personally use), Django's reverse function will automatically provide the right url to get to the django_select2_central_json view.

Also check out the documentation on Django's url dispatcher.

like image 61
knbk Avatar answered Mar 30 '23 00:03

knbk