diff options
author | Sage Abdullah <me@laymonage.com> | 2023-04-19 23:54:18 +0700 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-19 20:51:42 +0200 |
commit | 01ae9d4ca9afdaf30a247e10e8333261a7d8224c (patch) | |
tree | b29edadc1423c6bb27bdf0f905431fd7beba9c73 /docs | |
parent | 5b5f5e4cc63446c9c83dc834a71994c6e026c881 (diff) | |
download | django-01ae9d4ca9afdaf30a247e10e8333261a7d8224c.tar.gz |
Fixed #34435 -- Doc'd that JSONField.default must be a callable.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/ref/models/fields.txt | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index 447668bbc5..27b87c1f53 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -1265,14 +1265,16 @@ Python native format: dictionaries, lists, strings, numbers, booleans and 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`. +.. 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 :class:`~django.db.models.Index` and :attr:`.Field.db_index` both create a |