有没有办法在Django REST Framework JSON API中显示有关关系字段的更多详细信息

时间:2018-06-11 14:13:58

标签: django django-rest-framework json-api

我试图使用Django REST框架JSON API,并且想知道是否有一种方法可以将关系序列化(ForeignKey和all)与以下内容进行更详细的比较:

"post": {
          "type": "Post",
          "id": 1
        }

我在考虑以下几点:

"post": {
          "type": "Post",
          "id": 1,
          "name": "First Post"
          "tag": "Development"
        }

1 个答案:

答案 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/