mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
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
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user