From 086cfa0dc35c86cb3112f30b36bdd06d3aabf4e6 Mon Sep 17 00:00:00 2001 From: kovacspe Date: Sat, 14 Dec 2024 23:11:13 +0100 Subject: [PATCH] =?UTF-8?q?Pridan=C3=BD=20po=C4=8Det=20odovzdan=C3=BDch=20?= =?UTF-8?q?a=20aopraven=C3=BDch=20rie=C5=A1en=C3=AD=20do=20seriliazeru=20P?= =?UTF-8?q?roblemu=20(#473)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- competition/serializers.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/competition/serializers.py b/competition/serializers.py index 3222368..83316e0 100644 --- a/competition/serializers.py +++ b/competition/serializers.py @@ -193,12 +193,16 @@ class ProblemSerializer(serializers.ModelSerializer): class Meta: model = models.Problem fields = '__all__' - read_only_fields = ['submitted', 'num_comments'] + read_only_fields = ['submitted', 'num_comments', + 'num_solutions', 'num_corrected_solutions'] submitted = serializers.SerializerMethodField( 'get_submitted') num_comments = serializers.SerializerMethodField( 'get_num_comments') + num_solutions = serializers.SerializerMethodField('get_num_solutions') + num_corrected_solutions = serializers.SerializerMethodField( + 'get_num_corrected_solutions') verbose_name = serializers.SerializerMethodField('get_verbose_name') # correction = ProblemCorrectionSerializer(many=False,) @@ -207,6 +211,12 @@ def get_num_comments(self, obj): user = self.context['request'].user if 'request' in self.context else AnonymousUser return len(list(obj.get_comments(user))) + def get_num_solutions(self, obj: models.Problem): + return obj.num_solutions + + def get_num_corrected_solutions(self, obj: models.Problem): + return obj.num_corrected_solutions + def get_submitted(self, obj): if 'request' in self.context: if (