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
Post a Comment