Open mpvillafranca opened 8 years ago
Add new serializer field:
class LegacyMultipleChoiceField(serializers.MultipleChoiceField):
def to_internal_value(self, value):
return ','.join(value)
serializer:
class HuecoSerializer(serializers.ModelSerializer):
tipo_proteccion = LegacyMultipleChoiceField(choices=your_choises)
class Meta:
model = Hueco
fields = ('id', 'tipo_proteccion' )
I've got some models with attributes which are
SelectMultipleField
. I'm using Django Rest Framework to serialize that models and send the data to an AngularJS app, but I've got a problem when I'm trying to update that fields via JSON. When I get the data from the server, I'm receiving an array of strings, but when I sent the update data back to the server with the same format, I'm getting an error: "This isn't a valid option". I've also tried to parse the data to strings splited by commas but it doesn't work either.... Any ideas of what I'm doing wrong?