Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pridaný počet odovzdaných a aopravených riešení do seriliazeru Problemu #473

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading