Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #18478 - Documented how to use a mutable default in a model field.

  • Loading branch information...
commit 6e2bb344e40dafdf462f6fb660837fa061faf549 1 parent 20ee727
Tim Graham authored September 08, 2012

Showing 1 changed file with 8 additions and 0 deletions. Show diff stats Hide diff stats

  1. 8  docs/ref/models/fields.txt
8  docs/ref/models/fields.txt
@@ -195,6 +195,14 @@ support tablespaces for indexes, this option is ignored.
195 195
 The default value for the field. This can be a value or a callable object. If
196 196
 callable it will be called every time a new object is created.
197 197
 
  198
+The default cannot be a mutable object (model instance, list, set, etc.), as a
  199
+reference to the same instance of that object would be used as the default
  200
+value in all new model instances. Instead, wrap the desired default in a
  201
+callable.  For example, if you had a custom ``JSONField`` and wanted to specify
  202
+a dictionary as the default, use a ``lambda`` as follows::
  203
+
  204
+    contact_info = JSONField("ContactInfo", default=lambda:{"email": "to1@example.com"})
  205
+
198 206
 ``editable``
199 207
 ------------
200 208
 

0 notes on commit 6e2bb34

Please sign in to comment.
Something went wrong with that request. Please try again.