This commit is contained in:
@@ -211,9 +211,10 @@ class TopicAdmin(OrderableAdminMixin, ModelAdmin):
|
||||
list_filter = ('status', 'category', 'is_pinned', 'created_at', 'related_product', 'related_service', 'related_course')
|
||||
search_fields = ('title', 'content', 'author__nickname')
|
||||
autocomplete_fields = ['author', 'related_product', 'related_service', 'related_course']
|
||||
filter_horizontal = ('likes',)
|
||||
inlines = [TopicMediaInline, ReplyInline]
|
||||
actions = ['reset_ordering', 'approve_topics', 'reject_topics']
|
||||
list_editable = ('status', 'is_pinned')
|
||||
list_editable = ('status', 'is_pinned', 'view_count')
|
||||
|
||||
@admin.action(description="批量通过审核")
|
||||
def approve_topics(self, request, queryset):
|
||||
@@ -245,7 +246,7 @@ class TopicAdmin(OrderableAdminMixin, ModelAdmin):
|
||||
|
||||
fieldsets = (
|
||||
('帖子内容', {
|
||||
'fields': ('title', 'status', 'category', 'content', 'is_pinned')
|
||||
'fields': ('title', 'status', 'category', 'content', 'is_pinned', 'likes')
|
||||
}),
|
||||
('关联信息', {
|
||||
'fields': ('author', 'related_product', 'related_service', 'related_course'),
|
||||
@@ -274,16 +275,17 @@ class TopicAdmin(OrderableAdminMixin, ModelAdmin):
|
||||
|
||||
@admin.register(Reply)
|
||||
class ReplyAdmin(ModelAdmin):
|
||||
list_display = ('short_content', 'topic', 'author', 'is_pinned', 'created_at')
|
||||
list_display = ('short_content', 'topic', 'author', 'is_pinned', 'like_count', 'created_at')
|
||||
list_filter = ('is_pinned', 'created_at')
|
||||
search_fields = ('content', 'author__nickname', 'topic__title')
|
||||
autocomplete_fields = ['author', 'topic', 'reply_to']
|
||||
filter_horizontal = ('likes',)
|
||||
list_editable = ('is_pinned',)
|
||||
inlines = [TopicMediaInline]
|
||||
|
||||
fieldsets = (
|
||||
('回复内容', {
|
||||
'fields': ('topic', 'reply_to', 'content')
|
||||
'fields': ('topic', 'reply_to', 'content', 'likes')
|
||||
}),
|
||||
('发布信息', {
|
||||
'fields': ('author', 'is_pinned', 'created_at')
|
||||
@@ -291,6 +293,10 @@ class ReplyAdmin(ModelAdmin):
|
||||
)
|
||||
readonly_fields = ('created_at',)
|
||||
|
||||
@display(description="点赞数")
|
||||
def like_count(self, obj):
|
||||
return obj.likes.count()
|
||||
|
||||
@display(description="内容摘要")
|
||||
def short_content(self, obj):
|
||||
return obj.content[:30] + '...' if len(obj.content) > 30 else obj.content
|
||||
|
||||
Reference in New Issue
Block a user