for field in FIELDS:
row = []
row.append("<tr>")
row.append("<td>" + str(myform.fields.get(field)) + "</td>")
row.append("</tr>")
custom_fields.append("".join(row))
When I give the custom_fields variable to the template, all I’m getting is:
<tr><td><django.forms.widgets.CheckboxInput object at 0x1fa7d90></td></tr>
How can I get the form rendered properly?
This is what I’m going to be doing eventually:
form1 = CustomForm1()
form2 = CustomForm2()
form3 = CustomForm3()
for field in FIELDS:
row = []
row.append("<tr>")
row.append("<td>" + str(form1.fields.get(field)) + "</td>")
row.append("<td>" + str(form2.fields.get(field)) + "</td>")
row.append("<td>" + str(form3.fields.get(field)) + "</td>")
row.append("</tr>")
custom_fields.append("".join(row))
So I can display all form fields together in one table.
I just figured this out. It’s
form[field]instead ofform.fields[field]so
form.fieldsis a list of all unbound fields, andform.__getitem__is a callable that returns the bound fields.