Skip to content

Instantly share code, notes, and snippets.

@richtier
Last active January 3, 2016 14:49
Show Gist options
  • Save richtier/8478456 to your computer and use it in GitHub Desktop.
Save richtier/8478456 to your computer and use it in GitHub Desktop.
serialize non django model
from rest_framework.views import APIView
from rest_framwrork import serializers
class NonDjangoModelSerializer(serializers.Serializer):
class Meta:
fields = ('field1', 'field1',)
field1 = serializers.Field()
field1 = serializers.Field()
class FooView(APIView):
serializer_class = NonDjangoModelSerializer
def get(self, request, *args, **kw):
...
my_data = argh_no_not_the_bees()
...
return Response(self.serializer_class(my_data).data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment