views:

50

answers:

1

I am storing a image location in my model field named as 'banner'.now in list_display page i want to show that field as a image rather than the name.I have made a function which is the location of image but i cant see the image instead that i am seening string

in my model banner is character varying field

any solution?

 def get_banner_image(obj):
    img = u''

    imgtag = mark_safe(u'<img src="http://www.asdd.com/%s"&gt;' % (obj.banner))
    img +=imgtag

    return mark_safe( '%s' % (img) )

And in my admin.py

list_display =(get_banner_image)

+3  A: 

Put this in your models.py

def get_banner_image(self):
    return u'<img src="http://www.asdd.com/%s" />' % (obj.banner)
get_banner_image.allow_tags = True

See the docs for more details (plus an example).

Dominic Rodger
how to import it
ha22109
got the answer for importing
ha22109
So did this answer work for you?
Dominic Rodger
It doesn't need to to in models.py any more - this can live in admin.py.
Daniel Roseman
@Daniel Roseman - thanks, didn't know that :)
Dominic Rodger