1
0
mirror of https://github.com/django/django.git synced 2025-10-26 15:16:09 +00:00

Fixed #25942 -- Fixed TypedChoiceField.has_changed with nullable field

This fixes a regression introduced by 871440361.
This commit is contained in:
Claude Paroz
2015-12-16 23:07:17 +01:00
parent 2ec23a3d41
commit d91cc25a2a
3 changed files with 16 additions and 6 deletions

View File

@@ -181,17 +181,16 @@ class Field(object):
"""
Return True if data differs from initial.
"""
# 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 w/ ''.
initial_value = initial if initial is not None else ''
try:
data = self.to_python(data)
if hasattr(self, '_coerce'):
data = self._coerce(data)
initial_value = self._coerce(initial_value)
return self._coerce(data) != self._coerce(initial)
except ValidationError:
return True
# 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 = initial if initial is not None else ''
data_value = data if data is not None else ''
return initial_value != data_value