mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #25718 -- Made a JSONField lookup value of None match keys that have a null value.
This commit is contained in:
committed by
Tim Graham
parent
4fe5d84666
commit
c979c0a2b8
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user