Django Rest framework, how to include '__all__' fields and a related field in ModelSerializer ?

前端 未结 7 2074
Happy的楠姐
Happy的楠姐 2020-12-01 05:09

I have two models, one with M2M relation and a related name. I want to include all fields in the serializer and the related field.

models.py:

<
7条回答
  •  青春惊慌失措
    2020-12-01 05:47

    to include all the fields and the other fields defined in your serializer you can just say exclude = ()

    class ToppingSerializer(serializers.HyperlinkedModelSerializer):
       pizzas = '<>' #the extra attribute value
        class Meta:
            model = Topping
            exclude = ()
    

    This will list all the field values with the extra argument pizzas

提交回复
热议问题