Search code examples
pythondjangodjango-adminadmin

Django-admin : How to display link to object info page instead of edit form , in records change list?


I am customizing Django-admin for an application am working on . so far the customization is working file , added some views . but I am wondering how to change the records link in change_list display to display an info page instead of change form ?!

in this blog post :http://www.theotherblog.com/Articles/2009/06/02/ extending-the-django-admin-interface/ Tom said :

" You can add images or links in the listings view by defining a function then adding my_func.allow_tags = True "

which i didn't fully understand !!

right now i have profile function , which i need when i click on a member in the records list i can display it ( or adding another button called - Profile - ) , also how to add link for every member ( Edit : redirect me to edit form for this member ) .

How i can achieve that ?!


Solution

  • If I understand your question right you want to add your own link to the listing view, and you want that link to point to some info page you have created.

    To do that, create a function to return the link HTML in your Admin object. Then use that function in your list. Like this:

    class ModelAdmin(admin.ModelAdmin):
        def view_link(self):
            return u"<a href='view/%d/'>View</a>" % self.id
        view_link.short_description = ''
        view_link.allow_tags = True
        list_display = ('id', view_link)