Last active
August 29, 2015 14:10
-
-
Save kurorido/9dee7c02d426614fc4fc to your computer and use it in GitHub Desktop.
restframework blog note
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
class ArticleSerializer(serializers.ModelSerializer): | |
tags = serializers.RelatedField(many=True) | |
class Meta: | |
model = Article | |
fields = ('title','content','tags') | |
owner = serializers.Field(source='owner.username') | |
class TagSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Tag | |
fields = ('tagName',) | |
class Tag(models.Model): | |
tag_name = models.CharField(max_length=100) | |
class Article(models.Model): | |
title = models.CharField(max_length=100) | |
content = models.TextField() | |
created = models.DateTimeField(auto_now_add=True) | |
tags = models.ManyToManyField(Tag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment