I have a model which contains sensitive data, let's say a social security number, I would like to transform that data on serialization to display only the last four digits.
I have the full social security number stored: 123-45-6789. I want my serializer output to contain: ***-**-6789
My model:
class Employee (models.Model): name = models.CharField(max_length=64,null=True,blank=True) ssn = models.CharField(max_length=16,null=True,blank=True) My serializer:
class EmployeeSerializer(serializers.ModelSerializer): id = serializers.ReadOnlyField() class Meta: model = Employee fields = ('id','ssn') read_only_fields = ['id']