Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raise ValidationError from pre_save receiver function?

I'd like to inform the user if something fails during processing of the data in instance in my pre_save receiver function.

Is it possible to raise a custom ValidationError from the receiver function? If not, how would I go about implementing something like this?

like image 787
jmagnusson Avatar asked Apr 26 '11 13:04

jmagnusson


1 Answers

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.

like image 182
Jocelyn delalande Avatar answered Nov 07 '22 04:11

Jocelyn delalande