diff options
| author | Artur Beltsov <artur1998g@gmail.com> | 2020-11-08 12:52:34 +0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-12-02 09:30:50 +0100 |
| commit | 48b4bae983a1f9a73624fe62ef5bd1130b0dba39 (patch) | |
| tree | fb4759d8fcaadd48f45c08cf28f080f52690a356 /docs | |
| parent | adb40d217ec57ade46b1394cfbf3c513dc669445 (diff) | |
Fixed #32179 -- Added JSONObject database function.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/database-functions.txt | 23 | ||||
| -rw-r--r-- | docs/releases/3.2.txt | 2 |
2 files changed, 25 insertions, 0 deletions
diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index 5d13f47879..948ce4e3cc 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -148,6 +148,29 @@ 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) + +.. versionadded:: 3.2 + +Takes a list of key-value pairs and returns a JSON object containing those +pairs. + +Usage example:: + + >>> 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`` --------- diff --git a/docs/releases/3.2.txt b/docs/releases/3.2.txt index 089e0c08c4..7d374da0a7 100644 --- a/docs/releases/3.2.txt +++ b/docs/releases/3.2.txt @@ -367,6 +367,8 @@ Models block exits without errors. A nested atomic block marked as durable will raise a ``RuntimeError``. +* Added the :class:`~django.db.models.functions.JSONObject` database function. + Pagination ~~~~~~~~~~ |
