I have a widget that allows user to enter data for a model field. The data in the form can't be directly converted to Python - it requires some coercion. Where do I put this code? Is the widget responsible for translating its post data to a python value? The field itself?
I thought that maybe value_from_datadict() would be correct, but now it looks like that serves a different purpose.
(I'm using the form in the admin interface, if it makes any difference.)
Update @AndiDog: I'm incredulous that to_python is what I want. From the Django source:
135     def to_python(self, value):
136         """
137         Converts the input value into the expected Python data type, raising
138         django.core.exceptions.ValidationError if the data can't be converted.
139         Returns the converted value. Subclasses should override this.
140         """
141         return value
You're saying that this is called with value being the POST data from the form? I put in a print statement, and value is None when submitting the form, even though the input has data.
Update 2: Actually, it looks like value_from_datadict is the way to go. It has a dictionary from names of inputs to their values.