Exclude a field from django rest framework serializer

前端 未结 2 733
你的背包
你的背包 2021-02-11 15:24

In the following serializer, I have a nested serializer [ContainerSerializer] field and I want to exclude a field from (container)ContainerSerializer b

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-11 15:44

    There is a fields meta property:

    class BLcontainerMergedSerializer(serializers.ModelSerializer):
        container = ContainerSerializer()
        class Meta:
            model = BLcontainer
            fields = ('field1', 'field2')
    

    Reference: Django REST docs

提交回复
热议问题