I want to define a setter
function for a Django model field in order to validate the input and immediately raise a error if value is not valid.
I don't think that doing the validation in save()
or pre_save()
is a feasible solution for my problem because of things beyond my control.
Also changing the field into a property and use plain field.getter
and field.setter
are not feasible as this will break .filter()
, .exclude()
etc on the field, plus it will require a scheme change even if I changed field
to _field
and overrode the manager.
So, am I forced to override __setattr__
or is there a better way of doing this?