diff options
| author | Dmitry Dygalo <dadygalo@gmail.com> | 2018-02-20 16:47:12 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-04-04 10:53:46 -0400 |
| commit | c979c0a2b8abca325a549961fd7a17bdc36bcb1f (patch) | |
| tree | b6d221918b9c0989cbb3d6dc08cd7ebee08381bf /docs | |
| parent | 4fe5d846666d46a5395a5f0ea2845a96b6837a75 (diff) | |
Fixed #25718 -- Made a JSONField lookup value of None match keys that have a null value.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/contrib/postgres/fields.txt | 19 | ||||
| -rw-r--r-- | docs/releases/2.1.txt | 4 |
2 files changed, 22 insertions, 1 deletions
diff --git a/docs/ref/contrib/postgres/fields.txt b/docs/ref/contrib/postgres/fields.txt index 4c910527c9..1837557665 100644 --- a/docs/ref/contrib/postgres/fields.txt +++ b/docs/ref/contrib/postgres/fields.txt @@ -544,7 +544,7 @@ name:: ... }], ... }, ... }) - >>> Dog.objects.create(name='Meg', data={'breed': 'collie'}) + >>> Dog.objects.create(name='Meg', data={'breed': 'collie', 'owner': None}) >>> Dog.objects.filter(data__breed='collie') <QuerySet [<Dog: Meg>]> @@ -566,6 +566,23 @@ the :lookup:`jsonfield.contains` lookup instead. If only one key or index is used, the SQL operator ``->`` is used. If multiple operators are used then the ``#>`` operator is used. +To query for ``null`` in JSON data, use ``None`` as a value:: + + >>> Dog.objects.filter(data__owner=None) + <QuerySet [<Dog: Meg>]> + +To query for missing keys, use the ``isnull`` lookup:: + + >>> Dog.objects.create(name='Shep', data={'breed': 'collie'}) + >>> Dog.objects.filter(data__owner__isnull=True) + <QuerySet [<Dog: Shep>]> + +.. versionchanged:: 2.1 + + In older versions, using ``None`` as a lookup value matches objects that + don't have the key rather than objects that have the key with a ``None`` + value. + .. warning:: Since any string could be a key in a JSON object, any lookup other than diff --git a/docs/releases/2.1.txt b/docs/releases/2.1.txt index 46a903ba11..8ad64f250a 100644 --- a/docs/releases/2.1.txt +++ b/docs/releases/2.1.txt @@ -372,6 +372,10 @@ Miscellaneous * Since migrations are now loaded from ``.pyc`` files, you might need to delete them if you're working in a mixed Python 2 and Python 3 environment. +* Using ``None`` as a :class:`~django.contrib.postgres.fields.JSONField` lookup + value now matches objects that have the specified key and a null value rather + than objects that don't have the key. + .. _deprecated-features-2.1: Features deprecated in 2.1 |
