Created
August 19, 2013 19:10
-
-
Save mmourafiq/6272831 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
from posts.models import Post | |
class PostSerializer(serializers.HyperlinkedModelSerializer): | |
author = serializers.Field(source='author.username') | |
api_url = serializers.SerializerMethodField('get_api_url') | |
class Meta: | |
model = Post | |
fields = ('id', 'title', 'description', 'created_on', 'author', 'url', 'api_url') | |
read_only_fields = ('id', 'created_on') | |
def get_api_url(self, obj): | |
return "#/post/%s" % obj.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment