Change clickable field in Django admin list_display

亡梦爱人 提交于 2019-12-22 01:27:01

问题


In Django 1.8.6, by default, whenever I provide a list_display option to a ModelAdmin subclass, the first field in the list becomes clickable and leads to the object edit page.

Is there a way to keep the order of the fields in list_display, but change the clickable one?

Currently, I have the id field clickable (it goes first in list_display), which is a tad small. I would like to better click on, say, name to go to the edit page.


回答1:


You could have a look at django.contrib.admin.ModelAdmin.list_display_links

Basically it is used like

class PersonAdmin(admin.ModelAdmin):
    list_display = ('first_name', 'last_name', 'birthday')
    list_display_links = ('first_name', 'last_name')

Hope this will help :)



来源:https://stackoverflow.com/questions/33616330/change-clickable-field-in-django-admin-list-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!