From d7d711c68cc070d9b6962f43f97ece097162adcc Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Sun, 15 Dec 2024 16:01:45 +0000 Subject: Refs #35718, Refs #32179 -- Moved JSONObject to django.db.models.functions.json. --- docs/ref/models/database-functions.txt | 55 ++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'docs') diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index eb08e160f7..f23585739e 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -163,31 +163,6 @@ and ``comment.modified``. The PostgreSQL behavior can be emulated using ``Coalesce`` if you know a sensible minimum value to provide as a default. -``JSONObject`` --------------- - -.. class:: JSONObject(**fields) - -Takes a list of key-value pairs and returns a JSON object containing those -pairs. - -Usage example: - -.. code-block:: pycon - - >>> from django.db.models import F - >>> from django.db.models.functions import JSONObject, Lower - >>> Author.objects.create(name="Margaret Smith", alias="msmith", age=25) - >>> author = Author.objects.annotate( - ... json_object=JSONObject( - ... name=Lower("name"), - ... alias="alias", - ... age=F("age") * 2, - ... ) - ... ).get() - >>> author.json_object - {'name': 'margaret smith', 'alias': 'msmith', 'age': 50} - ``Least`` --------- @@ -861,6 +836,36 @@ that deal with time-parts can be used with ``TimeField``: 2014-06-16 00:00:00+10:00 2 2016-01-01 04:00:00+11:00 1 +.. _json-functions: + +JSON Functions +============== + +``JSONObject`` +-------------- + +.. class:: JSONObject(**fields) + +Takes a list of key-value pairs and returns a JSON object containing those +pairs. + +Usage example: + +.. code-block:: pycon + + >>> from django.db.models import F + >>> from django.db.models.functions import JSONObject, Lower + >>> Author.objects.create(name="Margaret Smith", alias="msmith", age=25) + >>> author = Author.objects.annotate( + ... json_object=JSONObject( + ... name=Lower("name"), + ... alias="alias", + ... age=F("age") * 2, + ... ) + ... ).get() + >>> author.json_object + {'name': 'margaret smith', 'alias': 'msmith', 'age': 50} + .. _math-functions: Math Functions -- cgit v1.3