Skip to content

Instantly share code, notes, and snippets.

@maryokhin
Created July 9, 2014 17:34
Show Gist options
  • Save maryokhin/43f0c951bbea943b95b9 to your computer and use it in GitHub Desktop.
Save maryokhin/43f0c951bbea943b95b9 to your computer and use it in GitHub Desktop.
class PostSerializer(ModelSerializer):
"""
General post serializer.
"""
url = ReverseField(view_name='post-instance')
channel = ChannelSerializer(read_only=True)
user = UserInstanceSerializer(read_only=True)
latest_comments = serializers.SerializerMethodField('get_latest_comments')
comments_url = ReverseField(view_name='post-comment-list')
channel_id = serializers.PrimaryKeyRelatedField(source='channel', write_only=True)
user_id = serializers.PrimaryKeyRelatedField(source='user', write_only=True)
class Meta():
model = Post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment