[Answered ]-Django writable nested serializers, create method not working

2👍

Try using different serializers for creation and representation.

class AdsCreateSerializer(serializers.ModelSerializer):

    class Meta:
        model = Ads
        fields = "__all__"
class AdsSerializer(serializers.ModelSerializer):

    display = DisplaySerializer()

    class Meta:
        model = Ads
        fields = "__all__"

-1👍

For display field, AdsSerializer expects the following structure;

"display": {"id": 91}

whereas you send this;

"display": 91
👤ebllg

Leave a comment