Matt Hoskins
unread,Dec 18, 2012, 4:46:36 AM12/18/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-d...@googlegroups.com
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