Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to allow only for create field in serializer

class TodoModifySerializer(ModelSerializer):

    def to_internal_value(self, data):
        data = super(TodoModifySerializer, self).to_internal_value(data)
        if self.instance:
            # update
            for x in self.create_only_fields:
                data.pop(x)
        return data

    class Meta:
        model = Todo
        fields = ('id', 'category', 'title', 'content')
        create_only_fields = ('title',)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #create #field #serializer
ADD COMMENT
Topic
Name
4+7 =