From 9168849e600b3c425f3760050edb263e70fb737e Mon Sep 17 00:00:00 2001 From: predatell <898242+predatell@users.noreply.github.com> Date: Mon, 27 Aug 2018 14:04:06 +0000 Subject: [PATCH 1/3] queryset from choices --- django_select2/forms.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/django_select2/forms.py b/django_select2/forms.py index c56be82d..4fca8bc4 100644 --- a/django_select2/forms.py +++ b/django_select2/forms.py @@ -415,6 +415,8 @@ def get_queryset(self): """ if self.queryset is not None: queryset = self.queryset + elif self.choices.queryset: + queryset = self.choices.queryset elif self.model is not None: queryset = self.model._default_manager.all() else: From 89708ea8affe9832cb1c36af6d7eeacea200cbef Mon Sep 17 00:00:00 2001 From: predatell <898242+predatell@users.noreply.github.com> Date: Tue, 28 Aug 2018 08:53:00 +0000 Subject: [PATCH 2/3] Update forms.py --- django_select2/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_select2/forms.py b/django_select2/forms.py index 4fca8bc4..6820aff7 100644 --- a/django_select2/forms.py +++ b/django_select2/forms.py @@ -415,7 +415,7 @@ def get_queryset(self): """ if self.queryset is not None: queryset = self.queryset - elif self.choices.queryset: + elif hasattr(self.choices, 'queryset'): queryset = self.choices.queryset elif self.model is not None: queryset = self.model._default_manager.all() From 9230c0abf16f24ffa0f840dbc018232cbd743a6d Mon Sep 17 00:00:00 2001 From: predatell Date: Tue, 9 Jul 2019 12:45:19 +0300 Subject: [PATCH 3/3] Widget queryset from ModelChoiceField queryset --- tests/testapp/forms.py | 2 -- 1 file changed, 2 deletions(-) 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,