diff options
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/database-functions.txt | 55 |
1 files changed, 30 insertions, 25 deletions
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 |
