new
All checks were successful
Deploy to Server / deploy (push) Successful in 36s

This commit is contained in:
jeremygan2021
2026-02-25 00:33:34 +08:00
parent 21f01fb0c4
commit 96c12b9e58
8 changed files with 71 additions and 20 deletions

View File

@@ -153,10 +153,11 @@ class TopicAdmin(ModelAdmin):
@admin.register(Reply)
class ReplyAdmin(ModelAdmin):
list_display = ('short_content', 'topic', 'author', 'created_at')
list_filter = ('created_at',)
list_display = ('short_content', 'topic', 'author', 'is_pinned', 'created_at')
list_filter = ('is_pinned', 'created_at')
search_fields = ('content', 'author__nickname', 'topic__title')
autocomplete_fields = ['author', 'topic', 'reply_to']
list_editable = ('is_pinned',)
inlines = [TopicMediaInline]
fieldsets = (
@@ -164,7 +165,7 @@ class ReplyAdmin(ModelAdmin):
'fields': ('topic', 'reply_to', 'content')
}),
('发布信息', {
'fields': ('author', 'created_at')
'fields': ('author', 'is_pinned', 'created_at')
}),
)
readonly_fields = ('created_at',)

View File

@@ -0,0 +1,22 @@
# Generated by Django 6.0.1 on 2026-02-24 16:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('community', '0012_activity_is_visible'),
]
operations = [
migrations.AlterModelOptions(
name='reply',
options={'ordering': ['-is_pinned', '-created_at'], 'verbose_name': '帖子回复', 'verbose_name_plural': '帖子回复管理'},
),
migrations.AddField(
model_name='reply',
name='is_pinned',
field=models.BooleanField(default=False, verbose_name='置顶'),
),
]

View File

@@ -186,6 +186,7 @@ class Reply(models.Model):
content = models.TextField(verbose_name="回复内容", help_text="支持Markdown格式")
author = models.ForeignKey(WeChatUser, on_delete=models.CASCADE, related_name='replies', verbose_name="回复者")
reply_to = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='children', verbose_name="回复楼层")
is_pinned = models.BooleanField(default=False, verbose_name="置顶")
created_at = models.DateTimeField(auto_now_add=True, verbose_name="回复时间")
def __str__(self):
@@ -194,7 +195,7 @@ class Reply(models.Model):
class Meta:
verbose_name = "帖子回复"
verbose_name_plural = "帖子回复管理"
ordering = ['created_at']
ordering = ['-is_pinned', '-created_at']
class TopicMedia(models.Model):

View File

@@ -91,7 +91,7 @@ class ReplySerializer(serializers.ModelSerializer):
class Meta:
model = Reply
fields = ['id', 'topic', 'content', 'author', 'author_info', 'reply_to', 'media', 'created_at', 'media_ids']
fields = ['id', 'topic', 'content', 'author', 'author_info', 'reply_to', 'media', 'created_at', 'media_ids', 'is_pinned']
read_only_fields = ['author', 'created_at']
def create(self, validated_data):