mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #25718 -- Made a JSONField lookup value of None match keys that have a null value.
This commit is contained in:
parent
4fe5d84666
commit
c979c0a2b8
9 changed files with 70 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue