We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6ae8792 commit abb7781Copy full SHA for abb7781
classroom/serializers/question.py
@@ -6,7 +6,7 @@
6
7
class ReadingQuestionSerializer(serializers.HyperlinkedModelSerializer):
8
choices = serializers.ListField(source='get_choices_content')
9
- answers = serializers.ListField(source='get_answers_content')
+ answers = serializers.SerializerMethodField()
10
11
class Meta:
12
model = ReadingQuestion
@@ -22,6 +22,13 @@ class Meta:
22
'number': {'min_value': 1},
23
}
24
25
+ def get_answers(self, question):
26
+ user = self.context['request'].user
27
+ if user.is_teacher():
28
+ return question.get_answers_content()
29
+ else:
30
+ return [] # Of course we can't allow student to see the answers
31
+
32
def validate(self, attrs):
33
attrs = super().validate(attrs)
34
self._validate_question_not_exist(attrs)
0 commit comments