Skip to content

Commit

Permalink
Pridaný počet odovzdaných a aopravených riešení do seriliazeru Proble…
Browse files Browse the repository at this point in the history
…mu (#473)
  • Loading branch information
kovacspe authored Dec 14, 2024
1 parent a6d6e1f commit 086cfa0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion competition/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)

Expand All @@ -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 (
Expand Down

0 comments on commit 086cfa0

Please sign in to comment.