fix view
This commit is contained in:
@@ -58,16 +58,31 @@ class CrawlTaskAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
@admin.register(CrawledContent)
|
@admin.register(CrawledContent)
|
||||||
class CrawledContentAdmin(admin.ModelAdmin):
|
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']
|
list_filter = ['website', 'task', 'created_at', 'publish_date', 'is_local_saved']
|
||||||
search_fields = ['title', 'content', 'keywords_matched']
|
search_fields = ['title', 'content', 'keywords_matched']
|
||||||
readonly_fields = ['created_at', 'preview_content', 'media_files_display']
|
readonly_fields = ['created_at', 'preview_content', 'media_files_display']
|
||||||
ordering = ['-created_at']
|
ordering = ['-created_at']
|
||||||
|
|
||||||
def title_short(self, obj):
|
class Media:
|
||||||
"""显示缩短的标题"""
|
css = {
|
||||||
return obj.title[:50] + '...' if len(obj.title) > 50 else obj.title
|
'all': ('admin/css/custom_admin.css',)
|
||||||
title_short.short_description = '标题'
|
}
|
||||||
|
|
||||||
|
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):
|
def media_count(self, obj):
|
||||||
"""显示媒体文件数量"""
|
"""显示媒体文件数量"""
|
||||||
|
|||||||
46
crawler/static/admin/css/custom_admin.css
Normal file
46
crawler/static/admin/css/custom_admin.css
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
自定义管理后台样式
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 增加标题列的宽度 */
|
||||||
|
.field-title_display {
|
||||||
|
width: 350px !important;
|
||||||
|
max-width: 350px !important;
|
||||||
|
min-width: 350px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 确保表格可以水平滚动 */
|
||||||
|
.results {
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 为标题单元格设置最小宽度 */
|
||||||
|
.results table tbody td.field-title_display,
|
||||||
|
.results table thead th.field-title_display {
|
||||||
|
min-width: 350px !important;
|
||||||
|
width: 350px !important;
|
||||||
|
max-width: 350px !important;
|
||||||
|
white-space: normal !important;
|
||||||
|
word-wrap: break-word !important;
|
||||||
|
word-break: break-word !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 为表头设置固定位置 */
|
||||||
|
.results table thead {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 强制表格列宽度 */
|
||||||
|
.results table {
|
||||||
|
table-layout: fixed !important;
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 特殊处理标题列 */
|
||||||
|
.change-list .results table tbody td:nth-child(1),
|
||||||
|
.change-list .results table thead th:nth-child(1) {
|
||||||
|
width: 350px !important;
|
||||||
|
min-width: 350px !important;
|
||||||
|
max-width: 350px !important;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user