Last active
January 3, 2016 14:49
-
-
Save richtier/8478456 to your computer and use it in GitHub Desktop.
serialize non django model
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.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