Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django model validation without using modelform

I wanted to do field validation on a django model without using ModelForms. Is there a way I can get the clean_fieldname method to be called when save() is invoked?

like image 945
pg2286 Avatar asked Jun 04 '26 02:06

pg2286


1 Answers

The clean_fieldname method belongs on a form or a model form. There's no code in the model to do the same thing, you'd have to implement it yourself.

I recommend you write a validator for your field, then call full_clean() before saving to validate your instance.

like image 94
Alasdair Avatar answered Jun 07 '26 14:06

Alasdair



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!