📜  通过序列化程序 django 设置值 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:39.852000             🧑  作者: Mango

代码示例1
class VariableSerializer(serializers.ModelSerializer):
    owner_name = serializers.Field(source='owner_id.owner_name')

    class Meta:
        model = Varmst
        resource_name = 'varmst'
        fields = ('varmst_id', 'varmst_type', 'varmst_name', 'varmst_value',
                  'varmst_desc')

    def transform_varmst_type(self, obj, value):
        if obj.varmst_value == 2:
            return "email"
        if obj.varmst_value == 3:
            return "Website"