diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-05-02 07:03:33 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-05-02 07:03:33 +0000 |
| commit | fbf5eaac9460a0f97187b80c9ac16b9aa023802e (patch) | |
| tree | 94569c7763cebdeafd3564e87f88a9a146387a16 /django | |
| parent | e43ace720cad6e0f000332e9dc4cba8af4be3bf6 (diff) | |
Fixed #10349 -- Modified ManyToManyFields to allow initial form values to be callables. Thanks to fas for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10652 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -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 f2723a18c7..679b37cfca 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -948,7 +948,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): |
