lib: don't order_by on widget because PolicyBindingModel, order in form

This commit is contained in:
Jens Langhammer 2021-03-01 19:23:09 +01:00
parent 88ce93ab04
commit 644a03e40e
4 changed files with 6 additions and 4 deletions

View File

@ -12,7 +12,7 @@ class ApplicationForm(forms.ModelForm):
def __init__(self, *args, **kwargs): # pragma: no cover def __init__(self, *args, **kwargs): # pragma: no cover
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields["provider"].queryset = ( self.fields["provider"].queryset = (
Provider.objects.all().order_by("pk").select_subclasses() Provider.objects.all().order_by("name").select_subclasses()
) )
class Meta: class Meta:

View File

@ -34,7 +34,8 @@ class FlowStageBindingForm(forms.ModelForm):
"""FlowStageBinding Form""" """FlowStageBinding Form"""
stage = GroupedModelChoiceField( stage = GroupedModelChoiceField(
queryset=Stage.objects.all().select_subclasses(), to_field_name="stage_uuid" queryset=Stage.objects.all().order_by("name").select_subclasses(),
to_field_name="stage_uuid",
) )
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):

View File

@ -10,7 +10,7 @@ class GroupedModelChoiceIterator(ModelChoiceIterator):
def __iter__(self): def __iter__(self):
if self.field.empty_label is not None: if self.field.empty_label is not None:
yield ("", self.field.empty_label) yield ("", self.field.empty_label)
queryset = self.queryset.order_by("name") queryset = self.queryset
# Can't use iterator() when queryset uses prefetch_related() # Can't use iterator() when queryset uses prefetch_related()
if not queryset._prefetch_related_lookups: if not queryset._prefetch_related_lookups:
queryset = queryset.iterator() queryset = queryset.iterator()

View File

@ -15,7 +15,8 @@ class PolicyBindingForm(forms.ModelForm):
to_field_name="pbm_uuid", to_field_name="pbm_uuid",
) )
policy = GroupedModelChoiceField( policy = GroupedModelChoiceField(
queryset=Policy.objects.all().select_subclasses(), required=False queryset=Policy.objects.all().order_by("name").select_subclasses(),
required=False,
) )
group = forms.ModelChoiceField( group = forms.ModelChoiceField(
queryset=Group.objects.all().order_by("name"), required=False queryset=Group.objects.all().order_by("name"), required=False