mirror of
https://github.com/django/django.git
synced 2024-12-28 03:55:50 +00:00
[4.2.x] Fixed #34435 -- Doc'd that JSONField.default must be a callable.
Backport of 01ae9d4ca9
from main
This commit is contained in:
parent
df44c7b3cc
commit
f80dbcf7dc
@ -1262,14 +1262,16 @@ Python native format: dictionaries, lists, strings, numbers, booleans and
|
|||||||
|
|
||||||
Defaults to ``json.JSONDecoder``.
|
Defaults to ``json.JSONDecoder``.
|
||||||
|
|
||||||
If you give the field a :attr:`~django.db.models.Field.default`, ensure it's an
|
|
||||||
immutable object, such as a ``str``, or a callable object that returns a fresh
|
|
||||||
mutable object each time, such as ``dict`` or a function. Providing a mutable
|
|
||||||
default object like ``default={}`` or ``default=[]`` shares the one object
|
|
||||||
between all model instances.
|
|
||||||
|
|
||||||
To query ``JSONField`` in the database, see :ref:`querying-jsonfield`.
|
To query ``JSONField`` in the database, see :ref:`querying-jsonfield`.
|
||||||
|
|
||||||
|
.. admonition:: Default value
|
||||||
|
|
||||||
|
If you give the field a :attr:`~django.db.models.Field.default`, ensure
|
||||||
|
it's a callable such as the :py:class:`dict` class or a function that
|
||||||
|
returns a fresh object each time. Incorrectly using a mutable object like
|
||||||
|
``default={}`` or ``default=[]`` creates a mutable default that is shared
|
||||||
|
between all instances.
|
||||||
|
|
||||||
.. admonition:: Indexing
|
.. admonition:: Indexing
|
||||||
|
|
||||||
:class:`~django.db.models.Index` and :attr:`.Field.db_index` both create a
|
:class:`~django.db.models.Index` and :attr:`.Field.db_index` both create a
|
||||||
|
Loading…
Reference in New Issue
Block a user