djangodjango-select2

django_select2 widget - "No results found"


I'm using django_select2 "ModelSelect2Widget" and get on html-form "No results found". What is wrong?

models.py

class Department(Catalog):
    name = models.CharField(max_length=50, unique=True)

class Person(Catalog):
    surname = models.CharField(max_length=50)
    name = models.CharField(max_length=50)
    department = models.ForeignKey(Department, on_delete=models.PROTECT)

forms.py

class MyWidget(ModelSelect2Widget):
    model = Department
    search_fields = ['name__icontains', ]


class PersonForm(ModelForm):
    class Meta:
        model = Person
        fields = ['surname', 'name', 'department']
        widgets = {'department': MyWidget}

Solution

  • It's my mistake. I have installed "SELECT2" exсept "django-select2". I disabled "SELECT2" by removing its links, but leave "django-select2" links. And now MyWidget works fine.