Skip to content

Instantly share code, notes, and snippets.

@agouil
Created January 29, 2016 17:23
Show Gist options
  • Save agouil/37d73786afab7da6037f to your computer and use it in GitHub Desktop.
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
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
Copy link

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment