mirror of
https://github.com/Hopiu/django-select2.git
synced 2026-05-01 10:24:44 +00:00
Try to get queryset form choices, if possible (#509)
Get queryset for model widgets from choices. This omits the need to explicitly supply a queryset or model to the widget.
This commit is contained in:
parent
6b1ca10b06
commit
8bd7f7209f
2 changed files with 2 additions and 2 deletions
|
|
@ -419,6 +419,8 @@ class ModelSelect2Mixin:
|
|||
"""
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue