1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #36085 -- Added JSONField support for negative array indexing on SQLite.

This commit is contained in:
savanto
2025-05-13 13:42:58 +02:00
committed by Sarah Boyce
parent a8716f3c4c
commit 8620a3b0c7
8 changed files with 73 additions and 1 deletions

View File

@@ -1092,6 +1092,8 @@ Unless you are sure you wish to work with SQL ``NULL`` values, consider setting
.. fieldlookup:: jsonfield.key
.. _key-index-and-path-transforms:
Key, index, and path transforms
-------------------------------
@@ -1134,6 +1136,22 @@ array:
>>> Dog.objects.filter(data__owner__other_pets__0__name="Fishy")
<QuerySet [<Dog: Rufus>]>
If the key is a negative integer, it cannot be used in a filter keyword
directly, but you can still use dictionary unpacking to use it in a query:
.. code-block:: pycon
>>> Dog.objects.filter(**{"data__owner__other_pets__-1__name": "Fishy"})
<QuerySet [<Dog: Rufus>]>
.. admonition:: MySQL, MariaDB, and Oracle
Negative JSON array indices are not supported.
.. versionchanged:: 6.0
SQLite support for negative JSON array indices was added.
If the key you wish to query by clashes with the name of another lookup, use
the :lookup:`contains <jsonfield.contains>` lookup instead.