Methods

Return the value that should be shown for this field on render of a
bound form, given the submitted POST data for the field and the initial
data, if any.
For most fields, this will simply be data; FileFields need to handle it
a bit differently.

defbound_data(self,data,initial):""" Return the value that should be shown for this field on render of a bound form, given the submitted POST data for the field and the initial data, if any. For most fields, this will simply be data; FileFields need to handle it a bit differently. """ifself.disabled:returninitialreturndata

Validates the given value and returns its "cleaned" value as an
appropriate Python object.
Raises ValidationError for any errors.

defclean(self,value):""" Validates the given value and returns its "cleaned" value as an appropriate Python object. Raises ValidationError for any errors. """value=self.to_python(value)self.validate(value)self.run_validators(value)returnvalue

defhas_changed(self,initial,data):""" Return True if data differs from initial. """try:data=self.to_python(data)ifhasattr(self,'_coerce'):returnself._coerce(data)!=self._coerce(initial)exceptValidationError:returnTrue# For purposes of seeing whether something has changed, None is# the same as an empty string, if the data or initial value we get# is None, replace it with ''.initial_value=initialifinitialisnotNoneelse''data_value=dataifdataisnotNoneelse''returninitial_value!=data_value