Search code examples
cssdjangoimageadminthumbnails

Magnify django thumbnail on mouse hover in django admin


How to add css hover effect to this django admin function that displays thumbnail in the admin section. To magnify the size of the image

def image_tag(self):
        if self.image:
            return mark_safe('<img src="%s" style="width: 50px; height:40px;" />' % self.image.url)
        else:
            return 'No Image Found'
    image_tag.short_description = 'Image'

Solution

  • Create a static directory inside of your django app->static->app_name->css->style.css

    Then in your admin.py you add the style like this

    class Media:   
        css = {
         'all': ('app_name/css/style.css',)
        }
    

    inside the model admin. example:

    class ModelNameAdmin(admin.ModelAdmin):
          class Media:   
                 css = {
                 'all': ('app_name/css/style.css',)
                }
    

    then write your custom css