Widget rendering and access to "parts" in a template

1 view
Skip to first unread message

Joseph Heck

unread,
May 14, 2007, 2:27:36 PM5/14/07
to django-d...@googlegroups.com
Good morning,

I have been looking at how to best provide a break-out of a few fields
in newforms to my template designers. In corresponding with Malcolm on
django-users, I found out that you couldn't break down the form input
into it's parts directly from within a template - primarily because
BoundField's as_widget() method always required at least one argument.

I would like to make a proposed patch to enable this for template
designers, but I'm afraid I'm lacking the background knowledge for the
how/why of some of the design choices. I'm hoping someone can
illuminate this for me.

When I dug around through the code, the RadioSelect widget stood out
in that it has this RadioFieldRenderer getting passed back instead of
just a unicode string. Another widget that seems to fit the same kind
of bill is the CheckboxSelectMultiple - but it wasn't set up with a
renderer object. What was the reason for setting up a renderer?

In both of these cases, I would like to make something so that a
template designer can access the component parts of one of these
composed widgets. So that the following are equivilants, each giving a
little "more" access for the template designers

{{ form.radiochoice }}

---

<ul>
{% for component in form.radiochoice %}
{{ component }}
{% endfor %}
</ul>

---

<ul>
{% for component in form.radiochoice %}
<li><label>{{ component.tag }} {{component.choice_label }}</label></li>
{% endfor %}
</ul>

Any thoughts on how I should/shouldn't normalize this to make this
possible? Or is there a place where I can read a little more on the
design background for these pieces?

Is this the kind of thing that should reside outside of the django
core? I think it would be beneficial, but I wanted to ask before I
started throwing in patches to modify it.

-joe

Gulopine

unread,
May 15, 2007, 9:07:22 AM5/15/07
to Django developers
I could definitely see some value in this for the widget I'm designing
for DurationField, as it would give template designers the ability to
display only part of the widget (such as minutes and seconds, for CD
audio information, for instance), while filling the rest in either in
the view or as hidden fields. I haven't worked with radio groups like
you describe, but it would be great if a single solution could work
for both that and MultiValueField subclasses (which would include
SplitDateTimeField and SplitDurationField).

-Gul

Reply all
Reply to author
Forward
0 new messages