[Fixed]-Raise ValidationError from pre_save receiver function?


You can raise whatever exception you want within the pre_save listener function, it will propagate to your save() call and prevent it from suceeding.

It will bubble up to where you call save(), from here, you can catch it (try/except…) and notify the user.


I guess you should either use Model.clean() method (http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#django.db.models.Model.clean) or form clean http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-clean-method.

Leave a comment