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 (