Image Widget (for admin)

 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

  1. ImageField for admin with thumbnail by semente 4 years ago
  2. GeoDjango maps in admin TabularInlines by alanB 2 years, 8 months ago
  3. Dynamic tabular inlines with optional drag-n-drop sorting by Aneon 4 years, 1 month ago
  4. Limit queryset to objects related to parent in ManyToMany fields within admin inlines by DrMeers 3 years ago
  5. EditInline for GenericForeignKey by king 5 years, 1 month ago

Comments

(Forgotten your password?)