Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.4.X] Fixed #18478 - Documented how to use a mutable default in a m…

…odel field.

Backport of 6e2bb34 from master
  • Loading branch information...
commit cd5181f84c7d4f2002efb777b6cf042771135f7a 1 parent b0e2cb8
@timgraham timgraham authored
Showing with 8 additions and 0 deletions.
  1. +8 −0 docs/ref/models/fields.txt
View
8 docs/ref/models/fields.txt
@@ -197,6 +197,14 @@ support tablespaces for indexes, this option is ignored.
The default value for the field. This can be a value or a callable object. If
callable it will be called every time a new object is created.
+The default cannot be a mutable object (model instance, list, set, etc.), as a
+reference to the same instance of that object would be used as the default
+value in all new model instances. Instead, wrap the desired default in a
+callable. For example, if you had a custom ``JSONField`` and wanted to specify
+a dictionary as the default, use a ``lambda`` as follows::
+
+ contact_info = JSONField("ContactInfo", default=lambda:{"email": "to1@example.com"})
+
``editable``
------------
Please sign in to comment.
Something went wrong with that request. Please try again.