Skip to content

Commit 7eca0ee

Browse files
Default field value is now "null", or None if null=True
1 parent 7c52947 commit 7eca0ee

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Add a ``JSONField`` to your model like any other field.
5959

6060
``JSONField`` also has a few additional optional parameters.
6161

62-
- ``default``: Falls back on ``{}`` if not provided.
62+
- ``default``: Falls back on ``"null"`` if not provided
6363
- ``db_type``: Allows you to specify the column type (default: ``text``)
6464
- ``encoder``: Custom JSON encoder (default: ``DjangoJSONEncoder``)
6565
- ``decoder``: Custom JSON decoder (default: ``json_field.fields.JSONDecoder``)

json_field/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, *args, **kwargs):
7575
decoder_kwargs.update({'cls':decoder})
7676
self.encoder_kwargs = encoder_kwargs
7777
self.decoder_kwargs = decoder_kwargs
78-
kwargs['default'] = kwargs.get('default', {} if not kwargs.get('null') else None)
78+
kwargs['default'] = kwargs.get('default', 'null')
7979
kwargs['help_text'] = kwargs.get('help_text', self.default_error_messages['invalid'])
8080
super(JSONField, self).__init__(*args, **kwargs)
8181

test_project/app/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def test_get_set_json(self):
7272
self.assertEqual({'test':123}, t1.json)
7373
self.assertEqual('{"test": 123}', t1.get_json_json())
7474
t2 = Test.objects.create()
75-
self.assertEqual({}, t2.json)
76-
self.assertEqual('{}', t2.get_json_json())
75+
self.assertEqual(None, t2.json)
76+
self.assertEqual('null', t2.get_json_json())
7777
self.assertEqual(None, t2.json_null)
7878
self.assertEqual('null', t2.get_json_null_json())
7979
t3 = Test.objects.create(json=[1,2,3])

0 commit comments

Comments
 (0)