You can definitely do this using field validation. How do you check if updating or creating checks for self.instance in the check function. There is a little mention of this in the serializer documentation .
self.instance will hold the existing object and its values, so you can use it for comparison.
I believe this should work for your purposes:
def validate_spouse(self, value): if self.instance and value != self.instance.spouse: raise serializers.ValidationError("Till death do us part!") return value
Another way to do this is to override if the field is read_only, if you are updating. This can be done in the __init__ serializer. Like a validator, you are just looking for an instance and if there is data:
def __init__(self, *args, **kwargs):
source share