Skip to content

Instantly share code, notes, and snippets.

@darklow
Created March 15, 2013 13:23
Show Gist options
  • Save darklow/5169832 to your computer and use it in GitHub Desktop.
Save darklow/5169832 to your computer and use it in GitHub Desktop.
class ReadOnlyWidget(forms.TextInput):
def render(self, name, value, attrs=None):
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.
final_attrs['value'] = force_unicode(self._format_value(value))
return mark_safe(u'<span%s />%s</span>' % (flatatt(final_attrs), value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment