So Im new to this and I am writing an api that takes a request with a field 
like this:

{ "content": "Some content" }


And I want to save this in  Story model in the db named "content" *but* i 
want it returned in the API with field post_content like so:

{ "post_content": "Some content" }


Here is my (stripped down) code:

class StorySerializer(serializers.ModelSerializer):

    post_content = serializers.CharField(source='content', required=False)

class Meta:
    model = Story
    fields = ('post_content')

class Story(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    content = models.TextField()

    class Meta:
        ordering = ('created',)


How do transform the "content" variable to "post_content"? I need it to be 
called post_content in the serializer for the data on the way out.

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to