summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAllen Jonathan David <allenajdjonathan@gmail.com>2022-08-30 22:56:18 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-09-16 05:36:57 +0200
commit10178197d57476f69688d4535e550a1ea3a5eac5 (patch)
tree28a39467978f63adc1b2f7cc9ede69cd73a0c29f /docs
parent3ba7f2e9069c54db6d6d9d2fd1945b2dbc935d9c (diff)
Fixed #33966 -- Added support for using KeyTextTransform from lookup.
Diffstat (limited to 'docs')
-rw-r--r--docs/releases/4.2.txt4
-rw-r--r--docs/topics/db/queries.txt27
2 files changed, 31 insertions, 0 deletions
diff --git a/docs/releases/4.2.txt b/docs/releases/4.2.txt
index e4394c5887..7ca4f0271e 100644
--- a/docs/releases/4.2.txt
+++ b/docs/releases/4.2.txt
@@ -216,6 +216,10 @@ Models
allows performing actions that can fail after a database transaction is
successfully committed.
+* The new :class:`KT() <django.db.models.fields.json.KT>` expression represents
+ the text value of a key, index, or path transform of
+ :class:`~django.db.models.JSONField`.
+
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt
index 6deeec5037..5114efb57d 100644
--- a/docs/topics/db/queries.txt
+++ b/docs/topics/db/queries.txt
@@ -1059,6 +1059,33 @@ To query for missing keys, use the ``isnull`` lookup::
:lookup:`istartswith`, :lookup:`lt`, :lookup:`lte`, :lookup:`gt`, and
:lookup:`gte`, as well as with :ref:`containment-and-key-lookups`.
+``KT()`` expressions
+~~~~~~~~~~~~~~~~~~~~
+
+.. versionadded:: 4.2
+
+.. module:: django.db.models.fields.json
+
+.. class:: KT(lookup)
+
+ Represents the text value of a key, index, or path transform of
+ :class:`~django.db.models.JSONField`. You can use the double underscore
+ notation in ``lookup`` to chain dictionary key and index transforms.
+
+ For example::
+
+ >>> from django.db.models.fields.json import KT
+ >>> Dog.objects.create(name="Shep", data={
+ ... "owner": {"name": "Bob"},
+ ... "breed": ["collie", "lhasa apso"],
+ ... })
+ <Dog: Shep>
+ >>> Dogs.objects.annotate(
+ ... first_breed=KT("data__breed__1"),
+ ... owner_name=KT("data__owner__name")
+ ... ).filter(first_breed__startswith="lhasa", owner_name="Bob")
+ <QuerySet [<Dog: Shep>]>
+
.. note::
Due to the way in which key-path queries work,