lib: sort GroupedModelChoiceField by name

closes #602
This commit is contained in:
Jens Langhammer 2021-03-01 18:30:27 +01:00
parent 19eea68e0f
commit 37b59bb5b9

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 queryset = self.queryset.order_by("name")
# 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()