django - Use a validator to modify/save a Field instead to raise an error -


in field of django model want user type dot ('.') @ end of textfield. otherwise want add it.

i've thought using validator seems it's not proper way it:

name = models.textfield(validators=[validate_dot])  def validate_dot(value):     if value:         if value[-1] != '.':             return value + '.' 

whay need change value of textfield (if required) not raise error.

what best approach achieve it?

you can override save() method on model.

def save(self, *args, **kwargs):     if not self.name.endswith("."):        self.name = self.name + "."     super(model, self).save(*args, **kwargs) 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -