Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions django/contrib/postgres/forms/hstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ def to_python(self, value):
for key, val in value.items():
value[key] = six.text_type(val)
return value

def has_changed(self, initial, data):
"""
Return True if data differs from initial.
"""
# For purposes of seeing whether something has changed, None is
# the same as an empty dict, if the data or initial value we get
# is None, replace it w/ {}.
initial_value = self.to_python(initial)
return super(forms.HStoreField, self).has_changed(initial_value, data)
6 changes: 6 additions & 0 deletions tests/postgres_tests/test_hstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ def test_model_field_formfield(self):
form_field = model_field.formfield()
self.assertIsInstance(form_field, forms.HStoreField)

def test_empty_field_has_not_changed(self):
class HStoreFormTest(forms.Form):
f1 = HStoreField()
form_w_hstore = HStoreFormTest()
self.assertFalse(form_w_hstore.has_changed())


class TestValidator(PostgresSQLTestCase):

Expand Down