#10427: Bound field needs an easy way to get form value
-------------------------------+--------------------------------------------
Reporter: toxik | Owner: nobody
Status: reopened | Milestone:
Component: Forms | Version: SVN
Resolution: | Keywords: form field value
Stage: Accepted | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
-------------------------------+--------------------------------------------
Comment (by zanuxzan):
As taken from the last patch, I think if your going to do this with a
template tag it should be as follows;
{{{
@register.filter(name='field_value')
def field_value(field):
"""
Returns the value for this BoundField, as rendered in widgets.
"""
if not field.form.is_bound:
val = field.form.initial.get(field.name, field.field.initial)
if callable(val):
val = val()
else:
if isinstance(field.field, FileField) and field.data is None:
val = field.form.initial.get(field.name, field.field.initial)
else:
val = field.data
if val is None:
val = ''
return val
@register.filter(name='display_value')
def display_value(field):
"""
Returns the displayed value for this BoundField, as rendered in
widgets.
"""
value = field.value
if isinstance(field.field, ChoiceField):
for (val, desc) in field.field.choices:
if val == value:
return desc
return field.value
display_value = property(_display_value)
}}}
The one above produced errors for me.
--
Ticket URL: <http://code.djangoproject.com/ticket/10427#comment:19>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---