diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-05-02 07:16:30 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-05-02 07:16:30 +0000 |
| commit | d22290b2ce00909c2f92b6dacadfbfb0deeefd7f (patch) | |
| tree | 304b41912345f7876762baa5a29e4a7e47ab4223 /django/db | |
| parent | 3c222b1b8be7c04578e50a66578b3a31a8ce70f5 (diff) | |
[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
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/fields/related.py | 5 |
1 files changed, 4 insertions, 1 deletions
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): |
