diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-12-30 00:12:02 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-12-30 00:12:02 +0000 |
| commit | b9fdf9abb841f1eda11fb4d8094372dbbbeb58cb (patch) | |
| tree | c8e0b24db0c347ddbd41c35346818955d7d59835 /django/db | |
| parent | 0919920bc0cf981da471717ce7000cfc9dabb077 (diff) | |
newforms: Got form_for_instance() to select initial ManyToManyField values properly
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4261 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/fields/related.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 433b5bde13..c4159d88fd 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -726,6 +726,10 @@ class ManyToManyField(RelatedField, Field): return getattr(obj, self.attname).all() def formfield(self, initial=None): + # If initial is passed in, it's a list of related objects, but the + # MultipleChoiceField takes a list of IDs. + if initial is not None: + initial = [i._get_pk_val() for i in initial] return forms.MultipleChoiceField(choices=self.get_choices_default(), required=not self.blank, label=capfirst(self.verbose_name), initial=initial) class ManyToOneRel(object): |
