feat: 批注 + 评分功能
This commit is contained in:
18
backend/diary/migrations/0006_comment_score.py
Normal file
18
backend/diary/migrations/0006_comment_score.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.11 on 2026-04-14 11:54
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('diary', '0005_comment'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='comment',
|
||||||
|
name='score',
|
||||||
|
field=models.IntegerField(blank=True, help_text='1-10 分', null=True, verbose_name='评分'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -104,6 +104,7 @@ class Comment(models.Model):
|
|||||||
content_type = models.CharField('内容类型', max_length=20, choices=CONTENT_TYPE_CHOICES)
|
content_type = models.CharField('内容类型', max_length=20, choices=CONTENT_TYPE_CHOICES)
|
||||||
object_id = models.IntegerField('内容 ID')
|
object_id = models.IntegerField('内容 ID')
|
||||||
content = models.TextField('批注内容')
|
content = models.TextField('批注内容')
|
||||||
|
score = models.IntegerField('评分', null=True, blank=True, help_text='1-10 分')
|
||||||
created_by = models.CharField('创建者', max_length=100, default='北极星')
|
created_by = models.CharField('创建者', max_length=100, default='北极星')
|
||||||
created_at = models.DateTimeField('创建时间', auto_now_add=True)
|
created_at = models.DateTimeField('创建时间', auto_now_add=True)
|
||||||
|
|
||||||
@@ -113,7 +114,8 @@ class Comment(models.Model):
|
|||||||
verbose_name_plural = '批注'
|
verbose_name_plural = '批注'
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.content_type} #{self.object_id} - {self.created_by}"
|
score_text = f' | {self.score}分' if self.score else ''
|
||||||
|
return f"{self.content_type} #{self.object_id} - {self.created_by}{score_text}"
|
||||||
|
|
||||||
|
|
||||||
class Task(models.Model):
|
class Task(models.Model):
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ class CommentSerializer(serializers.ModelSerializer):
|
|||||||
model = Comment
|
model = Comment
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
read_only_fields = ['created_at']
|
read_only_fields = ['created_at']
|
||||||
|
extra_kwargs = {
|
||||||
|
'content': {'required': False},
|
||||||
|
'score': {'required': False}
|
||||||
|
}
|
||||||
|
|
||||||
class ExperienceSerializer(serializers.ModelSerializer):
|
class ExperienceSerializer(serializers.ModelSerializer):
|
||||||
category_display = serializers.CharField(source='get_category_display', read_only=True)
|
category_display = serializers.CharField(source='get_category_display', read_only=True)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user