【发布时间】:2017-11-10 00:06:32
【问题描述】:
按照this 回答我想在我的管理页面中添加一个链接列,
class AnswerAdmin(admin.ModelAdmin):
list_display = ('__str__', 'link_to_question', 'time_created', 'time_updated', 'created_by', 'down_vote', 'up_vote')
def link_to_question(self, obj):
link = urlresolvers.reverse("admin:QnA_question_change",
args=[obj.question.id]) # model name has to be lowercase
text = obj.question.__str__
str = format_html("{}", text)
return mark_safe(u'<a href="%s">%s</a>' % (link, str))
class Meta:
model = Answer
但我得到的回报是:
<bound method Entry.__str__ of <Question: This is a question about technology?>>
我只想在我的管理员中显示“这是一个问题...”部分。
旁注: 当我使用 obj.question.text 之类的东西而不是函数时,它可以顺利运行。
【问题讨论】:
-
应该是
text = obj.question.__str__()
标签: python django django-admin