Skip to content

Instantly share code, notes, and snippets.

@agouil
agouil / list_serializer.py
Created January 29, 2016 17:23
A custom serializer for list fields to work with Django REST Framework < 3.0
from rest_framework import serializers
class ListSerializer(serializers.Serializer):
def from_native(self, data):
if isinstance(data, list):
return list(data)
else:
msg = self.error_messages['invalid']
raise serializers.ValidationError(msg)