I have overridden the update method for one of my serializers to call a model's method before saving the object. Like so:
class MyModelSerializer(serializers.ModelSerializer):
class Meta:
model = MyModel
fields = [...]
def update(self, instance, validated_data):
instance.model_method()
instance.save()
return instance
In my views, I am saving the serializer using serializer.save(), and of course setting it using MyModelSerializer(instance, data=request.data). However, my instance is not being saved. Just removing the update method saves the instance, but does not call the model_method() obviously. How can I fix this issue? Thanks for any help.
model_methoddo? Does it modify any attributes of the instance?super()call at the end ie after 1st line instead of callinginstance.save().