﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19138	Failed to pull initial data while Creating ModelForm instance with a prefix	Charlie.Tang@…	nobody	"ModelForm 's initial with a prefix failed to pull initial data

Example
{{{
class Project(models.Model):
    name = models.CharField(max_length=64,)

class Document(models.Model):
    project = models.ForeignKey(Project, )

class DocumentForm(ModelForm):
    class Meta:
        model = Document
}}}

The following with prefix='document' failed to have the initial selected in the dropdown list:
{{{
    form = DocumentForm(data={'project': a_Project_instance}, prefix='document')
}}}
But the following worked fine:
{{{
    form = DocumentForm(data={'project': a_Project_instance}, prefix='document')
}}}
[[BR]]

fix:

{{{
diff -r c04f07d5be28 django/forms/forms.py
--- a/django/forms/forms.py	Tue Oct 02 15:49:55 2012 -0400
+++ b/django/forms/forms.py	Wed Oct 17 10:32:33 2012 -0400
@@ -477,7 +477,7 @@
         """"""
         Returns the data for this BoundField, or None if it wasn't given.
         """"""
-        return self.field.widget.value_from_datadict(self.form.data, self.form.files, self.html_name)
+        return self.field.widget.value_from_datadict(self.form.data, self.form.files, self.name)
     data = property(_data)
 
     def value(self):

}}}


Problem: the keys of self.form.data is model's field_name, self.html_name has a prefix if the form's prefix is not None
"	Bug	closed	Forms	1.4	Normal	fixed	ModelForm instance prefix form.data html_name name		Unreviewed	1	0	0	0	0	0
