Description

Custom Validation: If you need to access other fields, you
need to overwrite form.clean(). If you want to have
the error message near a widget (not all), you need to
modify the _error dict of the form.

Perhaps a better method would be to have the ErrorDict be a defaultdict, that way users can do form._errorsfield?.append('error message') without worrying about whether or not field is in the dict or not.

Attached patch implements ErrorDict as a defaultdict (can't inherit directly from defaultdict since it's new in 2.5 or 2.4, can't remember, but definitely not in 2.3). It would be helpful if someone could review the documentation part of the patch since I'm not a native english speaker.

The docs look ok by me, 2 small things though, instead of self.has_key(field) do field in self . Also there's no need to use super() for setitem since it isn't overode in the subclass, you can actually just use setattr(self, field, []).

The method would either have to be on the Form class (not entirely insane). Another way how to propagate your error onto a field is using ComplexValidators present in model-validation branch, that way you don't have to worry about the internals of ErrorDict...

I agree that this is not the best way forwards. The ticket #20867 is now covering the Form.add_errors() approach. I'm going to close this ticket as a "duplicate" cos I think that's closest to what's happening.