Hello I have a form with ChoiceField whose widget is set to RadioSelect
Now to override default html output one needs to subclass RadioFieldRenderer like this:
class SimpleRadioFieldRenderer(forms.widgets.RadioFieldRenderer):
def render(self):
"""Outputs widget without <ul> or <li> tags."""
return mark_sa开发者_开发问答fe(u'\n'.join([u'%s'
% force_unicode(w.tag()) for w in self]))
All is good now except I'd like to be able to render 1 radio button at a time from template. Something like this:
{{ form.myfield.0 }}}
Or perhaps hanging it onto widget itself:
{{ form.myfield.field.widget.0 }}
What bugs me is that RadioFieldRenderer already implements __get_item__
to get just one RadioInput. The problem is that the renderer does not contain data, neither does the widget. And I'd really hate to mess with Field and BoundField.
I need this to inject html before/after each radiobutton and I'd like it to be done in the template. From the code it would be easy.
Any ideas are welcome.
I think this post in django-users may provide a way to do it (with an accessor function in the form class): http://groups.google.com/group/django-users/msg/b60410692c7c60e2
精彩评论