commit
All checks were successful
Deploy to Server / deploy (push) Successful in 27s

This commit is contained in:
jeremygan2021
2026-03-11 22:47:35 +08:00
parent 5a87105ec9
commit dbd752b833
7 changed files with 259 additions and 124 deletions

View File

@@ -80,8 +80,26 @@ class ScoreSerializer(serializers.ModelSerializer):
class CommentSerializer(serializers.ModelSerializer):
judge_name = serializers.CharField(source='judge.user.nickname', read_only=True)
score = serializers.SerializerMethodField()
class Meta:
model = Comment
fields = ['id', 'project', 'judge', 'content', 'judge_name', 'created_at']
fields = ['id', 'project', 'judge', 'content', 'judge_name', 'created_at', 'score']
read_only_fields = ['judge']
def get_score(self, obj):
scores = Score.objects.filter(project=obj.project, judge=obj.judge)
if not scores.exists():
return None
current_judge_total_score = 0
current_judge_total_weight = 0
for score in scores:
current_judge_total_score += score.score * score.dimension.weight
current_judge_total_weight += score.dimension.weight
if current_judge_total_weight > 0:
judge_score = current_judge_total_score / current_judge_total_weight
return round(judge_score, 1)
return None