From d22290b2ce00909c2f92b6dacadfbfb0deeefd7f Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 2 May 2009 07:16:30 +0000 Subject: [1.0.X] Fixed #10349 -- Modified ManyToManyFields to allow initial form values to be callables. Thanks to fas for the report and patch. Merge of r10652 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10653 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/fields/related.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'django/db') diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 0a7bb86e92..c2c07b8c94 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -943,7 +943,10 @@ class ManyToManyField(RelatedField, Field): # If initial is passed in, it's a list of related objects, but the # MultipleChoiceField takes a list of IDs. if defaults.get('initial') is not None: - defaults['initial'] = [i._get_pk_val() for i in defaults['initial']] + initial = defaults['initial'] + if callable(initial): + initial = initial() + defaults['initial'] = [i._get_pk_val() for i in initial] return super(ManyToManyField, self).formfield(**defaults) def db_type(self): -- cgit v1.3