We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我确定我已经查看了 (标注[ ]为[x])
[ ]
[x]
我要申请 (标注[ ]为[x])
comments.admin
class CommentAdmin(admin.ModelAdmin)
class CommentAdmin(admin.ModelAdmin): ...省略... def link_to_article(self, obj): info = (obj.author._meta.app_label, obj.author._meta.model_name) link = reverse('admin:%s_%s_change' % info, args=(obj.article.id,)) # print(link) return format_html( u'<a href="%s">%s</a>' % (link, obj.article.title))
BUG表现:当使用管理员账号在评论应用管理后台点击评论所属文章进行跳转不成功 点击跳转后:
失效原因: 我们将print(link)打开,可以在终端看到如下:
print(link)
此处我们需要的是文章的相关详细,而并非用户信息 解决方法:在def link_to_article(self, obj):中修改info信息的获取
def link_to_article(self, obj):
info
class CommentAdmin(admin.ModelAdmin): ...省略... # 其余不变 def link_to_article(self, obj): # 修改info,从文章模型中获取信息 info = (obj.article._meta.app_label, obj.article._meta.model_name) link = reverse('admin:%s_%s_change' % info, args=(obj.article.id,)) # print(link) return format_html( u'<a href="%s">%s</a>' % (link, obj.article.title))
即可解决问题,解决后输出如下: 点击后即可正常跳转:
当前大体环境配置: Django==4.2.14 Windows10 MySQL==8.0
Django==4.2.14
Windows10
MySQL==8.0
The text was updated successfully, but these errors were encountered:
No branches or pull requests
我确定我已经查看了 (标注
[ ]
为[x]
)我要申请 (标注
[ ]
为[x]
)comments.admin
中的class CommentAdmin(admin.ModelAdmin)
中BUG表现:当使用管理员账号在评论应用管理后台点击评论所属文章进行跳转不成功
点击跳转后:
失效原因:
我们将
print(link)
打开,可以在终端看到如下:此处我们需要的是文章的相关详细,而并非用户信息
解决方法:在
def link_to_article(self, obj):
中修改info
信息的获取即可解决问题,解决后输出如下:
点击后即可正常跳转:
当前大体环境配置:
Django==4.2.14
Windows10
MySQL==8.0
The text was updated successfully, but these errors were encountered: