Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8bd7f72

Browse files
predatellcodingjoe
authored andcommitted
Try to get queryset form choices, if possible (applegrew#509)
Get queryset for model widgets from choices. This omits the need to explicitly supply a queryset or model to the widget.
1 parent 6b1ca10 commit 8bd7f72

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

‎django_select2/forms.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ def get_queryset(self):
419419
"""
420420
if self.queryset is not None:
421421
queryset = self.queryset
422+
elif hasattr(self.choices, 'queryset'):
423+
queryset = self.choices.queryset
422424
elif self.model is not None:
423425
queryset = self.model._default_manager.all()
424426
else:

‎tests/testapp/forms.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ class AddressChainedSelect2WidgetForm(forms.Form):
186186
queryset=Country.objects.all(),
187187
label='Country',
188188
widget=ModelSelect2Widget(
189-
model=Country,
190189
search_fields=['name__icontains'],
191190
max_results=500,
192191
dependent_fields={'city': 'cities'},
@@ -198,7 +197,6 @@ class AddressChainedSelect2WidgetForm(forms.Form):
198197
queryset=City.objects.all(),
199198
label='City',
200199
widget=ModelSelect2Widget(
201-
model=City,
202200
search_fields=['name__icontains'],
203201
dependent_fields={'country': 'country'},
204202
max_results=500,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /