[Answer]-Remove first 3 characters from a field in the database

1👍

One time all-db change:

for doctor in Doctor.objects.all():
   doctor.name = doctor.name[3:]
   doctor.save()

If you just need to mask the name for some use cases only, you can use a property field in your model

class Doctor(Model):
   name = CharField(...)

   @property
   def masked_name(self):
       return self.name[3:]

   # To access to property you just use doctor.masked_name on an instance of the Doctor class (it's a property, you don't have to call doctor.masked_name())
👤bakkal

Leave a comment