delect a little of admin manager parts

This commit is contained in:
2025-10-27 03:35:20 +08:00
parent 15cedbcb95
commit 1fd902fb88

View File

@@ -144,56 +144,56 @@ class CrawledContentAdmin(admin.ModelAdmin):
media_files_display.short_description = '媒体文件' media_files_display.short_description = '媒体文件'
@admin.register(CrawlLog) # @admin.register(CrawlLog)
class CrawlLogAdmin(admin.ModelAdmin): # class CrawlLogAdmin(admin.ModelAdmin):
list_display = ['level', 'message_short', 'website', 'task', 'created_at'] # list_display = ['level', 'message_short', 'website', 'task', 'created_at']
list_filter = ['level', 'website', 'task', 'created_at'] # list_filter = ['level', 'website', 'task', 'created_at']
search_fields = ['message'] # search_fields = ['message']
readonly_fields = ['created_at'] # readonly_fields = ['created_at']
ordering = ['-created_at'] # ordering = ['-created_at']
#
def message_short(self, obj): # def message_short(self, obj):
"""显示缩短的消息""" # """显示缩短的消息"""
return obj.message[:100] + '...' if len(obj.message) > 100 else obj.message # return obj.message[:100] + '...' if len(obj.message) > 100 else obj.message
message_short.short_description = '消息' # message_short.short_description = '消息'
@admin.register(MediaFile) # @admin.register(MediaFile)
class MediaFileAdmin(admin.ModelAdmin): # class MediaFileAdmin(admin.ModelAdmin):
list_display = ['content', 'media_type', 'file_size_display', 'mime_type', 'created_at'] # list_display = ['content', 'media_type', 'file_size_display', 'mime_type', 'created_at']
list_filter = ['media_type', 'created_at'] # list_filter = ['media_type', 'created_at']
search_fields = ['content__title', 'original_url', 'alt_text'] # search_fields = ['content__title', 'original_url', 'alt_text']
readonly_fields = ['created_at', 'file_size_display', 'media_preview'] # readonly_fields = ['created_at', 'file_size_display', 'media_preview']
ordering = ['-created_at'] # ordering = ['-created_at']
#
def media_preview(self, obj): # def media_preview(self, obj):
"""媒体文件预览""" # """媒体文件预览"""
if obj.media_type == 'image' and obj.local_file: # if obj.media_type == 'image' and obj.local_file:
return format_html( # return format_html(
'<img src="/media/{}" style="max-width: 200px; max-height: 200px;" />', # '<img src="/media/{}" style="max-width: 200px; max-height: 200px;" />',
obj.local_file.name # obj.local_file.name
) # )
elif obj.media_type == 'video' and obj.local_file: # elif obj.media_type == 'video' and obj.local_file:
return format_html( # return format_html(
'<video controls style="max-width: 200px; max-height: 200px;"><source src="/media/{}" type="{}"></video>', # '<video controls style="max-width: 200px; max-height: 200px;"><source src="/media/{}" type="{}"></video>',
obj.local_file.name, # obj.local_file.name,
obj.mime_type # obj.mime_type
) # )
elif obj.media_type == 'audio' and obj.local_file: # elif obj.media_type == 'audio' and obj.local_file:
return format_html( # return format_html(
'<audio controls><source src="/media/{}" type="{}"></audio>', # '<audio controls><source src="/media/{}" type="{}"></audio>',
obj.local_file.name, # obj.local_file.name,
obj.mime_type # obj.mime_type
) # )
else: # else:
return "无预览" # return "无预览"
media_preview.short_description = '预览' # media_preview.short_description = '预览'
@admin.register(SearchKeyword) # @admin.register(SearchKeyword)
class SearchKeywordAdmin(admin.ModelAdmin): # class SearchKeywordAdmin(admin.ModelAdmin):
list_display = ['keyword', 'is_active', 'created_at', 'last_used'] # list_display = ['keyword', 'is_active', 'created_at', 'last_used']
list_filter = ['is_active', 'created_at', 'last_used'] # list_filter = ['is_active', 'created_at', 'last_used']
search_fields = ['keyword'] # search_fields = ['keyword']
list_editable = ['is_active'] # list_editable = ['is_active']
ordering = ['-last_used', '-created_at'] # ordering = ['-last_used', '-created_at']