Refs #35718, Refs #32179 -- Moved JSONObject to django.db.models.functions.json.

This commit is contained in:
Sage Abdullah 2024-12-15 16:01:45 +00:00 committed by Sarah Boyce
parent d36ad43f61
commit d7d711c68c
6 changed files with 98 additions and 89 deletions

View file

@ -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