From b7671d6e6a014a5fe546fdedb5ce428ac15ecd13 Mon Sep 17 00:00:00 2001 From: James Andres Date: Tue, 16 Dec 2014 10:35:32 -0800 Subject: [PATCH] Support for named groups in choices --- multiselectfield/db/fields.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/multiselectfield/db/fields.py b/multiselectfield/db/fields.py index 7e065a0..ee459c5 100644 --- a/multiselectfield/db/fields.py +++ b/multiselectfield/db/fields.py @@ -65,9 +65,15 @@ def get_choices_default(self): return self.get_choices(include_blank=False) def get_choices_selected(self, arr_choices): + named_groups = arr_choices and isinstance(arr_choices[0][1], (list, tuple)) choices_selected = [] - for choice_selected in arr_choices: - choices_selected.append(string_type(choice_selected[0])) + if named_groups: + for choice_group_selected in arr_choices: + for choice_selected in choice_group_selected[1]: + choices_selected.append(string_type(choice_selected[0])) + else: + for choice_selected in arr_choices: + choices_selected.append(string_type(choice_selected[0])) return choices_selected def value_to_string(self, obj):