fix: MultipleChoiceField use ordered sort

(cherry picked from commit 8436483e66)
This commit is contained in:
fbz 2025-07-05 04:16:36 +08:00
parent 3038494705
commit cc77c105b7

View File

@ -1469,17 +1469,17 @@ class MultipleChoiceField(ChoiceField):
if not self.allow_empty and len(data) == 0: if not self.allow_empty and len(data) == 0:
self.fail('empty') self.fail('empty')
return { # Arguments for super() are needed because of scoping inside
# Arguments for super() are needed because of scoping inside # comprehensions.
# comprehensions. return list(dict.fromkeys([
super(MultipleChoiceField, self).to_internal_value(item) super(MultipleChoiceField, self).to_internal_value(item)
for item in data for item in data
} ]))
def to_representation(self, value): def to_representation(self, value):
return { return list(dict.fromkeys([
self.choice_strings_to_values.get(str(item), item) for item in value self.choice_strings_to_values.get(str(item), item) for item in value
} ]))
class FilePathField(ChoiceField): class FilePathField(ChoiceField):