views:

642

answers:

1

I have a TabularInline admin layout, all works fine except I'd like to have it show something other than the Obj.__unicode__ value on the top left of each row.

My TabularInline is a photologue ImageModel model, so I'd like it to show me the thumbnail instead of the regular __unicode__ result.

I tried to change __unicode__ to output the thumbnail, which works, except the HTML is escaped so I get <img src="XXX"...... etc

Is there an easy way to mark my __unicode__ method as a safe string? Or a way to override the property the admin chooses to display?

I've tried this:

__unicode__.is_safe = True 

But that doesn't work.

+1  A: 

You can customize the template for you TabularInline to make it look the way you want. I think it's a better idea then hacking __unicode__:

class PhotoInline(admin.TabularInline):
    model = Photo
    template = 'photologue/photoinline.html'

You will most like create your template by coping and customising default django/contrib/admin/templates/admin/edit_inline/tabular.html template.

Ludwik Trammer
yes - that's the way I'd go - I've since created a new Widget to show the image (copied from djangosnippets)
Guy Bowden