@@ -122,28 +122,32 @@ def get_selected_values(form, field_name):
122122 form .is_valid ()
123123 filter_data = form .cleaned_data .get (field_name )
124124 field = form .fields [field_name ]
125- # Selection field
126- if hasattr (field , 'choices' ):
127- try :
128- choices = unpack_grouped_choices (field .choices )
129-
130- if hasattr (field , 'null_option' ):
131- # If the field has a `null_option` attribute set and it is selected,
132- # add it to the field's grouped choices.
133- if field .null_option is not None and None in filter_data :
134- choices .append ((settings .FILTERS_NULL_CHOICE_VALUE , field .null_option ))
135-
136- return [
137- label for value , label in choices if str (value ) in filter_data or None in filter_data
138- ]
139- except TypeError :
140- # Field uses dynamic choices. Show all that have been populated.
141- return [
142- subwidget .choice_label for subwidget in form [field_name ].subwidgets
143- ]
144125
145126 # Non-selection field
146- return [str (filter_data )]
127+ if not hasattr (field , 'choices' ):
128+ return [str (filter_data )]
129+
130+ # Get choice labels
131+ if type (field .choices ) is forms .models .ModelChoiceIterator :
132+ # Field uses dynamic choices: show all that have been populated on the widget
133+ values = [
134+ subwidget .choice_label for subwidget in form [field_name ].subwidgets
135+ ]
136+
137+ else :
138+ # Static selection field
139+ choices = unpack_grouped_choices (field .choices )
140+ values = [
141+ label for value , label in choices if str (value ) in filter_data or None in filter_data
142+ ]
143+
144+ if hasattr (field , 'null_option' ):
145+ # If the field has a `null_option` attribute set and it is selected,
146+ # add it to the field's grouped choices.
147+ if field .null_option is not None and None in filter_data :
148+ values .append (field .null_option )
149+
150+ return values
147151
148152
149153def add_blank_choice (choices ):
0 commit comments