简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM