On Thu, Dec 3, 2009 at 9:05 AM, Todd Blanchard <[email protected]> wrote:
> Forms seem nifty, but sometimes I want to display the data in the same
> format but readonly. Is there a to do this? I can't seem to find it.
I found this gizmo for doing that sort of thing:
class ShowOnly(forms.Widget):
"""
Show only the data do NOT have a input field
"""
input_type = 'hidden'
def render(self, name, value, attrs=None):
from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode
if value is None: value = ''
final_attrs = self.build_attrs(attrs, type=self.input_type,
name=name)
if value != '':
# Only add the 'value' attribute if a value is non-empty.
value = force_unicode(value)
final_attrs['value'] = force_unicode(value)
return mark_safe(u'<input%s />%s' %
(forms.util.flatatt(final_attrs),value))
I found it here:
http://www.djangosnippets.org/snippets/1185/
Nick
(tempted not to respond due to the "deafening silence" comment... did you
imagine you're due an instant answer?)
--
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.