1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | class ImageWidget(forms.FileInput):
"""
A ImageField Widget that shows a thumbnail.
"""
def __init__(self, attrs={}):
super(ImageWidget, self).__init__(attrs)
def render(self, name, value, attrs=None):
output = []
if value and hasattr(value, "url"):
output.append(('<a rel="facebox" target="_blank" href="%s">'
'<img class="photo" src="%s" style="height: 100px;" /></a> <br/>'
% (value.url, value.url)))
output.append(super(ImageWidget, self).render(name, value, attrs))
return mark_safe(u''.join(output))
|
More like this
- ImageField for admin with thumbnail by semente 4 years ago
- GeoDjango maps in admin TabularInlines by alanB 2 years, 8 months ago
- Dynamic tabular inlines with optional drag-n-drop sorting by Aneon 4 years, 1 month ago
- Limit queryset to objects related to parent in ManyToMany fields within admin inlines by DrMeers 3 years ago
- EditInline for GenericForeignKey by king 5 years, 1 month ago
Comments