Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2022-02-15 08:05:12 +01:00
parent 5b3d7fcf2c
commit 8af7ac8af4
71 changed files with 19992 additions and 19476 deletions

View File

@@ -11,7 +11,7 @@ class GroupedModelChoiceIterator(ModelChoiceIterator):
super().__init__(field)
def __iter__(self):
if self.field.empty_label is not None: # pragma: no cover
if self.field.empty_label is not None: # pragma: no cover
yield ("", self.field.empty_label)
queryset = self.queryset
# Can't use iterator() when queryset uses prefetch_related()
@@ -25,7 +25,9 @@ class GroupedModelChoiceField(ModelChoiceField):
def __init__(self, *args, choices_groupby, **kwargs):
if isinstance(choices_groupby, str):
choices_groupby = attrgetter(choices_groupby)
elif not callable(choices_groupby): # pragma: no cover
raise TypeError('choices_groupby must either be a str or a callable accepting a single argument')
self.iterator = partial(GroupedModelChoiceIterator, groupby=choices_groupby)
elif not callable(choices_groupby): # pragma: no cover
raise TypeError(
'choices_groupby must either be a str or a callable accepting a single argument')
self.iterator = partial(
GroupedModelChoiceIterator, groupby=choices_groupby)
super().__init__(*args, **kwargs)