码迷,mamicode.com
首页 > 其他好文 > 详细

ListSerializer

时间:2019-09-09 13:10:53      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:而不是   bsp   ted   any   数组   col   ida   date   else   

class TrackListSerializer(serializers.ListSerializer):
    def create(self, validated_data):
      #validated_data会返回所有请求数组,而不是单个对象
        print(validated_data)
        books = [Track(**item) for item in validated_data]
        return Track.objects.bulk_create(books)
    def to_internal_value(self, data):
        print(to_internal_value,data)
        return data.get(data)
class TrackSerializer(serializers.ModelSerializer):
    # album = AlbumField(queryset=Album.objects.all())

    class AlbumSerilaizer(serializers.ModelSerializer):
        class Meta:
            model = Album
            fields = "__all__"
    album = AlbumSerilaizer(many=False,read_only=True)
    class Meta:
        model = Track
        fields = "__all__"
        list_serializer_class = TrackListSerializer

 

ListSerializer

标签:而不是   bsp   ted   any   数组   col   ida   date   else   

原文地址:https://www.cnblogs.com/zhouze/p/11491015.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!