更新时间:2023-11-30 16:23:40
将此添加到您的模型中:
Add this to your model:
def user_link(self):
return '<a href="%s">%s</a>' % (reverse("admin:auth_user_change", args=(self.user.id,)) , escape(self.user))
user_link.allow_tags = True
user_link.short_description = "User"
您可能还需要将以下内容添加到 models.py
的顶部:
You might also need to add the following to the top of models.py
:
from django.template.defaultfilters import escape
from django.core.urls import reverse
在admin.py
中,在list_display
中,添加user_link
:
list_display = ('name', 'user_link', )
不需要 list_display_links
.