I needed to do a similar thing... in my case I needed the radio inputs
in separate table cells.
The way I did it was to write a custom widget, but I'd also be
interested to hear of another way to achieve the same thing.
Cheers,
Nick
On May 7, 3:53 am, "Joseph Heck" <[EMAIL PROTECTED]> wrote:
> I'm missing the connection in newforms to get to the pieces I want to
> manipulate in the templates.
>
> I have a newform with a single ChoiceField, set up with a RadioSelect()
> widget:
>
> example_choices = ((1,'a'),
> (2,'b'),
> (3,'c'),)
>
> class ExampleForm(forms.Form):
> choices =
> forms.ChoiceField(choices=example_choices,widget=forms.RadioSelect())
>
> def exampleview(request):
> form = ExampleForm()
> return render_to_response('example.html', {'form': form})
>
> When I get that into the template, I can get to the choices:
> {{form.choices}}
> which renders out the <ul><li...</ul> bits.
>
> In the newforms tests
> (http://code.djangoproject.com/browser/django/trunk/tests/regressionte...),
> there's an example where it appears that you can get to the individual
> pieces of that list set, and I'd like to be able to pull those apart
> in the template and render that up a little differently from the
> default.
>
> As far as I understand it, {{form.choices}} is handing back a
> BoundField object to the template context to work with - but I don't
> know how I can delve through that to get to the RadioFieldRenderer,
> where I can pull apart the choice list to more detail.
>
> I'm hoping that I can write out something like this in a template to
> style it up a little differently:
>
> <ul class="myclass">
> {% for rb in form.choices.something %}
> {{ rb }}
> {% endfor %}
>
> Or even break it down farther and use rb.name, rb.value,
> rb.choice_value, and rb.choice_label to display up the radio button
> selection pieces. "rb" in this case being the RadioInput objects that
> are shown in the tests
> athttp://code.djangoproject.com/browser/django/trunk/tests/regressionte...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---