djangodjango-rest-frameworkmultiplechoicefield

Django Rest Framework mulitplechoicefield - int not iterable


I am beginning to use and implement the Django Rest Framework and I have an issue with the multiple choice field.

My variable "CHOICES" looks like the following

(('0', 'Read Only'), ('5', 'Operator 1'), ('7', 'Operator 2'), ('100', 'Supervisor 1'), ('102', 'Supervisor 2'), ('255', 'Administrator'))

and the line that sets the field looks like

access = serializers.MultipleChoiceField(choices=CHOICES, allow_blank=False)

but I get the following error

File "C:\Python27\lib\site-packages\rest_framework\fields.py", line 1348, in to_representation self.choice_strings_to_values.get(six.text_type(item), item) for item in value TypeError: 'int' object is not iterable

when going into fields.py and printing the value, it is just a 255

I have tried explicitly iterating the current list and adding the items to a new array, but same problem.

What am I missing?


Solution

  • Changed "MultipleChoiceField" to "ChoiceField" and it works great. I guess I misunderstood the "MultipleChoiceField"