views:

24

answers:

1

I am trying to display a bound ModelForm in my template.

Here the the code from the view:

assessment = Assessment.objects.get(slug=slug)
form = AssessmentForm(assessment)

But when I then pull up the template, it is empty except for the submit button.

When I try to debug with PDB, I get:

(Pdb) form.data
<Assessment: Alaska - Coastal Forests>
(Pdb) form.as_p
<bound method AssessmentForm.as_p of <cst.assessapp.models.AssessmentForm object at 0x224b190>>
(Pdb) form.as_p()
*** AttributeError: 'Assessment' object has no attribute 'get'

So, obviously, I am doing something wrong. Can somebody help?

Thanks

+5  A: 

You have to pass the Assessment instance to the form class using the instance keyword argument.

form = AssessmentForm(instance = assessment)

See the documentation for more details.

Manoj Govindan