55👍
✅
You should use clean to do validation-related work, and to parse/change/otherwise clean the input. Capitalizing fields and generating a slug can happen here. I also use clean to force a field like post_type
to a specific value in proxy models. If you raise django.core.exceptions.ValidationError('error text')
inside clean, the 'error text'
is added to the form.non_field_errors
.
Save is the place to change the way a model is actually saved. For instance, I’ve used save to create a crop of an uploaded picture. ValidationError
s are not caught if raised here, and I feel like that’s the most important practical difference between the two.
Source:stackexchange.com