summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2015-12-16 23:07:17 +0100
committerClaude Paroz <claude@2xlibre.net>2015-12-17 15:39:34 +0100
commitff077cd6496b6f82195e2dc040f70e19e7c206c9 (patch)
tree526db2a2df95513350e9daf3bc523f00fdefb1ee /django/forms
parent54295a95d9b34dadb17054b88d43b2b769ccc0f3 (diff)
[1.9.x] Fixed #25942 -- Fixed TypedChoiceField.has_changed with nullable field
This fixes a regression introduced by 871440361. Backport of d91cc25a2a from master.
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/fields.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 85e7219cd4..d2ae133486 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -191,17 +191,16 @@ class Field(six.with_metaclass(RenameFieldMethods, 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