我试图使用Django REST框架JSON API,并且想知道是否有一种方法可以将关系序列化(ForeignKey和all)与以下内容进行更详细的比较:
"post": {
"type": "Post",
"id": 1
}
我在考虑以下几点:
"post": {
"type": "Post",
"id": 1,
"name": "First Post"
"tag": "Development"
}
答案 0 :(得分:0)
class AlbumSerializer(serializers.ModelSerializer):
tracks = serializers.StringRelatedField(many=True)
class Meta:
model = Album
fields = ('album_name', 'artist', 'tracks')
表示关系:http://www.django-rest-framework.org/api-guide/relations/