mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
This commit is contained in:
parent
d36ad43f61
commit
d7d711c68c
6 changed files with 98 additions and 89 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue