[Django]-Set serializer field from data value having different names (Custom field Mapping for ModelSerizer)

3👍

You can explicitly define type field inside serializer, and use source argument to map it to msg_type field:

class TruRouteRequestSerializer(serializers.ModelSerializer):
    type = serializers.CharField(source='msg_type')

    class Meta:
        model = TruRouteRequest
        fields = ['type', ...]

Leave a comment