The validation documentation for forms says that to_python on the form 
field is the first step in validation. I've written some code (the details 
of which don't really matter) which makes use of to_python on fields in 
doing so I discovered that "to_python" on ModelMultipleChoiceField doesn't 
work. The reason for this is that ModelMultipleChoiceField inherits from 
ModelChoiceField but then puts everything into "clean" and doesn't do 
anything about "to_python".

I would guess it was quicker/easier to put everything together in "clean" 
when the method was originally authored?

Given "to_python" is documented in forms as being a first step it feels to 
me untidy, at least, that this "to_python" is hanging around on 
ModelMultipleChoiceField in a non-working state and also that everything is 
put into "clean" - it would feel tidier to move the "to_python"-ish parts 
of ModelMultipleChoiceField out of "clean" and into "to_python". I also 
wonder if the "required" and "invalid_choice" tests from "clean" ought to 
be put into a "validate" method to make it consistent with how other fields 
behave, although I note from ModelChoiceField that an invalid choice cannot 
be converted to python since an instance can't be found for it so maybe 
to_python is the appropriate place for the invalid_choice test at least! I 
describe as "untidy" rather than as a bug as I'm not clear whether the 
documentation on validation is suggesting fields should have a "to_python" 
method and/or whether it's reasonable to expect "to_python" methods (if 
they exist) on form fields should work.

Worth me raising this as a ticket? Or is it a non-issue or there's a valid 
reason for keeping things as they are in ModelMultipleChoiceField's clean 
method?

Matt

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-developers/-/Uex-m8HYproJ.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to