Loading django/contrib/postgres/forms/hstore.py +10 −0 Original line number Diff line number Diff line Loading @@ -34,3 +34,13 @@ class HStoreField(forms.CharField): 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) docs/releases/1.8.3.txt +3 −1 Original line number Diff line number Diff line Loading @@ -15,5 +15,7 @@ Bugfixes * Fixed crash during :djadmin:`makemigrations` if a migrations module either is missing ``__init__.py`` or is a file (:ticket:`24848`). * Fixed ``exists()`` returning incorrect results after annotation with * Fixed ``QuerySet.exists()`` returning incorrect results after annotation with ``Count()`` (:ticket:`24835`). * Corrected ``HStoreField.has_changed()`` (:ticket:`24844`). tests/postgres_tests/test_hstore.py +7 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ from django.contrib.postgres import forms from django.contrib.postgres.fields import HStoreField from django.contrib.postgres.validators import KeysValidator from django.core import exceptions, serializers from django.forms import Form from django.test import TestCase from .models import HStoreModel Loading Loading @@ -174,6 +175,12 @@ class TestFormField(TestCase): form_field = model_field.formfield() self.assertIsInstance(form_field, forms.HStoreField) def test_empty_field_has_not_changed(self): class HStoreFormTest(Form): f1 = HStoreField() form_w_hstore = HStoreFormTest() self.assertFalse(form_w_hstore.has_changed()) class TestValidator(TestCase): Loading Loading
django/contrib/postgres/forms/hstore.py +10 −0 Original line number Diff line number Diff line Loading @@ -34,3 +34,13 @@ class HStoreField(forms.CharField): 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)
docs/releases/1.8.3.txt +3 −1 Original line number Diff line number Diff line Loading @@ -15,5 +15,7 @@ Bugfixes * Fixed crash during :djadmin:`makemigrations` if a migrations module either is missing ``__init__.py`` or is a file (:ticket:`24848`). * Fixed ``exists()`` returning incorrect results after annotation with * Fixed ``QuerySet.exists()`` returning incorrect results after annotation with ``Count()`` (:ticket:`24835`). * Corrected ``HStoreField.has_changed()`` (:ticket:`24844`).
tests/postgres_tests/test_hstore.py +7 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ from django.contrib.postgres import forms from django.contrib.postgres.fields import HStoreField from django.contrib.postgres.validators import KeysValidator from django.core import exceptions, serializers from django.forms import Form from django.test import TestCase from .models import HStoreModel Loading Loading @@ -174,6 +175,12 @@ class TestFormField(TestCase): form_field = model_field.formfield() self.assertIsInstance(form_field, forms.HStoreField) def test_empty_field_has_not_changed(self): class HStoreFormTest(Form): f1 = HStoreField() form_w_hstore = HStoreFormTest() self.assertFalse(form_w_hstore.has_changed()) class TestValidator(TestCase): Loading