views:

13

answers:

1

Hi Stackers'

I'd like to some little customisation with the django admin -- particularly the changelist_view

class FeatureAdmin(admin.ModelAdmin):
    list_display = (
        'content_object_change_url',
        'content_object',
        'content_type',
        'active',
        'ordering',
        'is_published',
    )

    list_editable = (
       'active',
       'ordering',
    )

    list_display_links = (
        'content_object_change_url',
    )

admin.site.register(get_model('features', 'feature'), FeatureAdmin)

The idea is that the 'content_object_change_url' could be a link to another object's change_view... a convenience for the admin user to quickly navigate directly to the item.

The other case I'd have for this kind of thing is adding links to external sources, or thumbnails of image fields.

I had thought I'd heard of a 'insert html' option -- but maybe I'm getting ahead of myself.

Thank you for your help!

+1  A: 

You can provide a custom method on the FeatureAdmin class which returns HTML for content_object_change_url:

class FeatureAdmin(admin.ModelAdmin):

    [...]

    def content_object_change_url(self, obj):
        return '<a href="%s">Click to change</a>' % obj.get_absolute_url()
    content_object_change_url.allow_tags=True

See the documentation.

Daniel Roseman
Ah ha! 'allow_tags'... I knew it was possible!
Daryl