Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

set value through serializer django

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"
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #set #serializer #django
ADD COMMENT
Topic
Name
4+1 =