This commit is contained in:
2025-10-27 05:02:56 +08:00
parent 68d0a48386
commit 8f9bca5dfa
2 changed files with 66 additions and 5 deletions

View File

@@ -58,16 +58,31 @@ class CrawlTaskAdmin(admin.ModelAdmin):
@admin.register(CrawledContent)
class CrawledContentAdmin(admin.ModelAdmin):
list_display = ['title_short', 'website', 'task', 'keywords_matched', 'media_count', 'publish_date', 'is_local_saved', 'created_at']
list_display = ['title_display', 'website', 'task', 'keywords_matched', 'media_count', 'publish_date', 'is_local_saved', 'created_at']
list_filter = ['website', 'task', 'created_at', 'publish_date', 'is_local_saved']
search_fields = ['title', 'content', 'keywords_matched']
readonly_fields = ['created_at', 'preview_content', 'media_files_display']
ordering = ['-created_at']
def title_short(self, obj):
"""显示缩短的标题"""
return obj.title[:50] + '...' if len(obj.title) > 50 else obj.title
title_short.short_description = '标题'
class Media:
css = {
'all': ('admin/css/custom_admin.css',)
}
def title_display(self, obj):
"""显示完整的标题,但在列表中限制宽度"""
if len(obj.title) > 100:
return format_html(
'<div style="min-width: 300px; white-space: normal; word-wrap: break-word;" title="{}">{}</div>',
obj.title,
obj.title[:100] + '...'
)
return format_html(
'<div style="min-width: 300px; white-space: normal; word-wrap: break-word;">{}</div>',
obj.title
)
title_display.short_description = '标题'
title_display.admin_order_field = 'title'
def media_count(self, obj):
"""显示媒体文件数量"""