provide django.forms field type info for use in templates
My use case is that it would be useful to have access to this info from templates when generating forms, eg:
{% for field in form.fields %}
{% if field.type == 'checkbox' %}
{# render one way... #}
{% else %}
{# render another way #}
{% endif %}
{% endfor %}
FWIW, django.contrib.admin seems to get around this problem in AdminField by adding an is_checkbox attribute, but it seems to me that the type of field being rendered should be easily available in the template, in other words, IMHO this makes sense as a core feature of django.forms.
Triage Stage: |
Unreviewed → Accepted
|
Owner: |
changed from nobody to rameshugar
|
Status: |
new → assigned
|
Owner: |
changed from rameshugar to David Smith
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
Broadly the idea has merit, but it needs a bit of finesse - specifically, what determines the "type" of the field? Do we just use the type of the input element on the widget? What do we do in the case of multi-widgets?
Unfortunately, the solution used in admin isn't a great reference point. Admin has control of all it's widgets, and the way in which they are used. This isn't true of the broader widget framework, which must integrate with arbitrary external widgets, used in unknown ways.