This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user