mirror of
https://github.com/django/django.git
synced 2025-08-02 01:53:15 +00:00
Fixed #32179 -- Added JSONObject database function.
This commit is contained in:
parent
adb40d217e
commit
48b4bae983
8 changed files with 161 additions and 2 deletions
|
@ -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``
|
||||
---------
|
||||
|
||||
|
|
|
@ -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
|
||||
~~~~~~~~~~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue