views:

14

answers:

2

I am trying to change the link for an object in the django admin list display. Here is what I have so far:

class FooModelAdmin(admin.ModelAdmin):
    fields = ('foo','bar')
    list_display = ('foo_link','bar')

    def foo_link(self,obj):
        return u'<a href="/foos/%s/">%s</a>' % (obj.foo,obj)
    domain_link.allow_tags = True
    domain_link.short_description = "foo"

This produces another link within the original list display link e.g.

<a href="/admin/app/model/pk/"><a href="/foos/foo/">Foo</a></a>
A: 

The solution was to override the init and set the list_display_links to None e.g.

class FooModelAdmin(admin.ModelAdmin):
    fields = ('foo','bar')
    list_display = ('foo_link','bar')

    def foo_link(self,obj):
        return u'<a href="/foos/%s/">%s</a>' % (obj.foo,obj)
    domain_link.allow_tags = True
    domain_link.short_description = "foo"
    def __init__(self,*args,**kwargs):
        super(FooModelAdmin, self).__init__(*args, **kwargs)
        self.list_display_links = (None, )
tomfmason
A: 

You need to override the template since the link is wrapped there. Have a look at http://stackoverflow.com/questions/1669104/edit-django-user-admin-template.

Andrew Sledge