Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to update only some fields in django serielizer update method

class HeroSerializer(serializers.ModelSerializer):
    class Meta:
        model=Hero
        fields=['id','name','secret_identity']


    def update(self, instance, validated_data):
        instance.secret_identity = validated_data.get('your field name', 'defaultvalue')
        instance.save()
        return instance
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #update #fields #django #serielizer #update #method
ADD COMMENT
Topic
Name
1+8 =