[1.8.x] Fixed #25233 -- Fixed HStoreField.has_changed() handling of initial values.
Thanks Simon Charette for review.
Backport of a7b7f27c05
from master
This commit is contained in:
parent
a7fb311ace
commit
ad2ac53054
|
@ -23,6 +23,7 @@ class HStoreField(forms.CharField):
|
|||
def to_python(self, value):
|
||||
if not value:
|
||||
return {}
|
||||
if not isinstance(value, dict):
|
||||
try:
|
||||
value = json.loads(value)
|
||||
except ValueError:
|
||||
|
|
|
@ -22,5 +22,5 @@ Bugfixes
|
|||
* Prevented an exception in ``TestCase.setUpTestData()`` from leaking the
|
||||
transaction (:ticket:`25176`).
|
||||
|
||||
* Fixed ``has_changed()`` method in
|
||||
:class:`django.contrib.postgres.forms.HStoreField`.
|
||||
* Fixed ``has_changed()`` method in ``contrib.postgres.forms.HStoreField``
|
||||
(:ticket:`25215`, :ticket:`25233`).
|
||||
|
|
|
@ -196,6 +196,12 @@ class TestFormField(TestCase):
|
|||
form_w_hstore = HStoreFormTest({'f1': '{"a": 2}'}, initial={'f1': '{"a": 1}'})
|
||||
self.assertTrue(form_w_hstore.has_changed())
|
||||
|
||||
form_w_hstore = HStoreFormTest({'f1': '{"a": 1}'}, initial={'f1': {"a": 1}})
|
||||
self.assertFalse(form_w_hstore.has_changed())
|
||||
|
||||
form_w_hstore = HStoreFormTest({'f1': '{"a": 2}'}, initial={'f1': {"a": 1}})
|
||||
self.assertTrue(form_w_hstore.has_changed())
|
||||
|
||||
|
||||
class TestValidator(TestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue