Django Rest Framework - Nested Serialization not working as expected

后端 未结 3 733
鱼传尺愫
鱼传尺愫 2021-02-07 17:32

While using Django-REST-Framework, I am not able to display selected fields in a nested serialized object.

I am correctly able to serialize the entirety of the Ad

3条回答
  •  你的背包
    2021-02-07 17:56

    Model Outlet has an "address" field, not an outlet_address. I would advise to set your serializer like this:

    class OutletSerializer(serializers.ModelSerializer):
        address = AddressSerializer(many=False)
    
        class Meta:
            model = Outlet
            fields = ('id', 'name', 'thumbnail', 'address')
            depth = 2
    

提交回复
热议问题