diff --git a/django_select2/forms.py b/django_select2/forms.py index 8317a7dd..55d52822 100644 --- a/django_select2/forms.py +++ b/django_select2/forms.py @@ -419,6 +419,8 @@ def get_queryset(self): """ if self.queryset is not None: queryset = self.queryset + elif hasattr(self.choices, 'queryset'): + queryset = self.choices.queryset elif self.model is not None: queryset = self.model._default_manager.all() else: diff --git a/tests/testapp/forms.py b/tests/testapp/forms.py index e858b7f1..976c3efc 100644 --- a/tests/testapp/forms.py +++ b/tests/testapp/forms.py @@ -186,7 +186,6 @@ class AddressChainedSelect2WidgetForm(forms.Form): queryset=Country.objects.all(), label='Country', widget=ModelSelect2Widget( - model=Country, search_fields=['name__icontains'], max_results=500, dependent_fields={'city': 'cities'}, @@ -198,7 +197,6 @@ class AddressChainedSelect2WidgetForm(forms.Form): queryset=City.objects.all(), label='City', widget=ModelSelect2Widget( - model=City, search_fields=['name__icontains'], dependent_fields={'country': 'country'}, max_results=500,