[Answered ]-DRF update resource with serializer with source argument

2👍

you should override the update function to update the primary_address.fax by yourself.

class UserSerializer(serializers.ModelSerializer):
    fax = serializers.CharField(source='primary_address.fax')

    def update(self, instance, validated_data):
        fax = validated_data.pop('fax', None)
        super(UserSerializer, self).update(instance, validated_data)
        if fax is not None:
            instance.primary_address.fax = fax
            instance.primary_address.save(update_fields=('fax',))
        return instance

Leave a comment