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.
The Django admin is a powerful built-in tool giving you the ability to create, update, and delete objects in your database using a web interface. You can customize the Django admin to do almost anything you want.
It provides a simple UI for creating, editing and deleting data defined with the Django ORM. In this article we are going to enable the admin user interface for a simple model and customize it from a simple list view to a more user friendly table like interface.
To view the default admin template you can access it in the django/contrib/admin/templates/admin folder. In this situation you will most likely be using a virtual environment and can find this folder in the directory that contains all the installed libraries.
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'
The easiest way to create your is to copy and customize the default django/contrib/admin/templates/admin/edit_inline/tabular.html
template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With