I remember trying to help you with this on IRC, Kurtis. I've had the same problem before, but I could never remember that BoundFields have a field attribute.. If there isn't a note in the docs (or even better, an example), I'll make sure to write a patch in the next few days.
Cheers, AT On 10/25/11, Kurtis <kurtis.mull...@gmail.com> wrote: > Thank you so much for this, Tom! I've asked this question quite a few > times in IRC and couldn't come across the answer I was looking for. I > figured it was possible, I just had no idea how to access it. Much > appreciation! > > On Oct 24, 11:26 am, Tom Evans <tevans...@googlemail.com> wrote: >> On Thu, Oct 20, 2011 at 8:37 PM, Kurtis <kurtis.mull...@gmail.com> wrote: >> > Hey, >> >> > I'm trying to build a custom template for my ModelForm. My ModelForm >> > contains several M2M fields. If I run the ModelForm.as_view and then >> > in my template print {{ form.as_p }} it'll automagically display those >> > choices. >> >> > Now what I want to do is take advantage of that magic and print out >> > those choices myself in my template. For example: >> >> > {% for choice in form.genres.choices %} >> > {{ choice }} >> > {% endfor %} >> >> > ... but it doesn't work. it doesn't print anything. I tried reading >> > through the source code of the forms.py and fields.py from 1.3 but >> > didn't get very far. >> >> When you access a form field from a template, the field returned is a >> BoundField, not the field attribute from the form class. From the >> BoundField object, you can access the form field on the field >> attribute, eg: >> >> {% for choice in form.genres.field.choices %} >> {{ choice }} >> {% endfor %} >> >> Cheers >> >> Tom > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Sent from my mobile device -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.