1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from django.template import Library
from django.template.defaultfilters import escape
register = Library()
@register.filter(name='field_str')
def field_str(bound_field):
field = bound_field.form.fields[bound_field.name]
if hasattr(field.widget,'choices'):
res = [x for x in field.widget.choices
if unicode(x[0]) == bound_field.data]
if len(res)>0:
return res[0][1]
return escape(bound_field.data)
|
More like this
- MultiSelectField with comma separated values (Field + FormField) by quinode 1 year ago
- MultipleChoiceCommaField by rubic 6 years, 2 months ago
- Rendering radio-buttons with icons instead of labels by jeverling 3 years, 2 months ago
- Complex Form Preview by smagala 4 years, 1 month ago
- Horizontal RadioSelect widget by gnrfan 1 year, 2 months ago
Comments
in django 1.0 u can use get_fieldname_display()
#