tags:

views:

72

answers:

2

Hi,

I have this admin.py

class LawyerAdmin(admin.ModelAdmin):
    fieldsets = [
        ('Name',   {'fields': ['last', 'first', 'firm_name', 'firm_url', 'school', 'year_graduated']}),
    ]
    list_display = ('last', 'first', 'school', 'year_graduated', 'firm_name', 'firm_url')
    list_filter = ['school', 'year_graduated']
    search_fields = ['last', 'school', 'firm_name']

and I want to make "firm_url" fields clickable with each of the url listed in the field. How can I do this? Thank you.

+9  A: 

Define a custom method in your LawyerAdmin class that returns the link as HTML:

def show_firm_url(self, obj):
    return '<a href="%s">%s</a>' % (obj.firm_url, obj.firm_url)
show_firm_url.allow_tags = True

See the documentation.

Daniel Roseman
Thanks! This works great.
Zeynel
A: 

add show_firm_url to list_display

diegueus9
Yes, I did and now it works, thanks. But it overrides the text display specified in my models and displays "show firm url" on the head of the column. I don't know if there is a way around it, but I changed "show_firm_url" to "Bio_link" and it's all fine now.
Zeynel