Created
March 15, 2013 13:23
-
-
Save darklow/5169832 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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