Created
January 29, 2016 17:23
-
-
Save agouil/37d73786afab7da6037f to your computer and use it in GitHub Desktop.
A custom serializer for list fields to work with Django REST Framework < 3.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
def to_native(self, obj): | |
return obj |
akramhussein
commented
Jan 29, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment