diff --git a/django_select2/widgets.py b/django_select2/widgets.py index fadf43e..e3c60ad 100644 --- a/django_select2/widgets.py +++ b/django_select2/widgets.py @@ -390,11 +390,16 @@ class HeavySelect2Mixin(Select2Mixin): selected_choices = list(force_unicode(v) for v in selected_choices) txts = [] all_choices = choices if choices else [] + choices_dict = dict() for val, txt in chain(self.choices, all_choices): val = force_unicode(val) - if val in selected_choices: - selected_choices = [v for v in selected_choices if v != val] - txts.append(txt) + choices_dict[val] = txt + for val in selected_choices: + try: + txts.append(choices_dict[val]) + except KeyError: + logger.error("Value '%s' is not a valid choice.", val) + if hasattr(self.field, '_get_val_txt') and selected_choices: for val in selected_choices: txt = self.field._get_val_txt(val) diff --git a/testapp/test.db b/testapp/test.db index 5cbdf95..cb93c08 100644 Binary files a/testapp/test.db and b/testapp/test.db differ