Просмотр исходного кода

Enforce consistent ordering of value/label keys for ChoiceField

Jeremy Stretch 7 лет назад
Родитель
Сommit
2bae50f501
1 измененных файлов с 5 добавлено и 1 удалено
  1. 5 1
      netbox/utilities/api.py

+ 5 - 1
netbox/utilities/api.py

@@ -71,7 +71,11 @@ class ChoiceField(Field):
     def to_representation(self, obj):
         if obj is '':
             return None
-        return {'value': obj, 'label': self._choices[obj]}
+        data = OrderedDict([
+            ('value', obj),
+            ('label', self._choices[obj])
+        ])
+        return data
 
     def to_internal_value(self, data):
         # Hotwiring boolean values