Django - How best to handle ValidationErrors after form.save(commit=False)
- by orokusaki
This is a fragment of my code from a view:
if form.is_valid():
instance = form.save(commit=False)
try:
instance.account = request.account
instance.full_clean()
except ValidationError, e:
# Do something with the errors here... I don't know what the best thing to do here is, but I certainly don't want to do it 180 times.
This is an utter mess. Who would want to handle validation errors manually in every view. If you're not modifying the instance after save(commit=False), you don't have to worry about this, but what about in my case where every model has a foreign key to account which is set behind the scenes and hidden from the user?
Any help is really appreciated.