[英]Django admin list_display show full text on mouse hover
There is a TextField named address .有一个名为address的 TextField 。 It usually contains more than 100 characters.
它通常包含 100 多个字符。 I can truncate the string but I want the following to happen: Full text should appear on mouse hover on the truncated part.
我可以截断字符串,但我希望发生以下情况: 完整文本应出现在鼠标 hover 上截断部分上。
If you don't need to edit the address in list_display
then you can just create a readonly field and use that:如果您不需要编辑
list_display
中的地址,那么您可以创建一个只读字段并使用它:
from django.utils.html import format_html
class MyAdmin(admin.ModelAdmin):
class Media:
css = {
'all': ("styles.css",)
}
list_display=(
...other fields,
list_display_address,
)
def list_display_address(self, instance):
return format_html(
'<span class="truncated_address" title="{}">{}</span>',
instance.address,
instance.address
)
styles.css
we can truncate the address if it's too long.styles.css
中,如果地址太长,我们可以截断地址。 (I'm assuming it is on a single line): .truncated_address{
text-overflow: ellipsis;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.