summaryrefslogtreecommitdiff
path: root/api/serializers.py
diff options
context:
space:
mode:
authorPalaparthy Adityachandra2020-05-13 16:32:29 +0530
committerGitHub2020-05-13 16:32:29 +0530
commit61d4096697a84873473ad28afb0dc79f211a54b3 (patch)
tree117068fb9a2ddef2a3a2dc81567ff07a3069f0bf /api/serializers.py
parent31e8b94b8ebf74d77cc8596411c6acfa2112f949 (diff)
parentb264b673a2f84def1b9736a7a596b1acd5bb4d72 (diff)
downloadonline_test-61d4096697a84873473ad28afb0dc79f211a54b3.tar.gz
online_test-61d4096697a84873473ad28afb0dc79f211a54b3.tar.bz2
online_test-61d4096697a84873473ad28afb0dc79f211a54b3.zip
Merge branch 'master' into change-create_question
Diffstat (limited to 'api/serializers.py')
-rw-r--r--api/serializers.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/api/serializers.py b/api/serializers.py
new file mode 100644
index 0000000..1c1e6a4
--- /dev/null
+++ b/api/serializers.py
@@ -0,0 +1,79 @@
+from rest_framework import serializers
+from yaksh.models import (
+ Question, Quiz, QuestionPaper, AnswerPaper, Course,
+ LearningModule, LearningUnit, Lesson
+)
+
+
+class QuestionSerializer(serializers.ModelSerializer):
+ test_cases = serializers.SerializerMethodField()
+
+ def get_test_cases(self, obj):
+ test_cases = obj.get_test_cases_as_dict()
+ return test_cases
+
+ class Meta:
+ model = Question
+ exclude = ('partial_grading', )
+
+
+class QuizSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = Quiz
+ exclude = ('view_answerpaper', )
+
+
+class QuestionPaperSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = QuestionPaper
+ fields = '__all__'
+
+
+class AnswerPaperSerializer(serializers.ModelSerializer):
+
+ questions = QuestionSerializer(many=True)
+
+ class Meta:
+ model = AnswerPaper
+ fields = '__all__'
+
+
+class LessonSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = Lesson
+ fields = '__all__'
+
+
+class LearningUnitSerializer(serializers.ModelSerializer):
+
+ quiz = QuizSerializer()
+ lesson = LessonSerializer()
+
+ class Meta:
+ model = LearningUnit
+ fields = '__all__'
+
+
+class LearningModuleSerializer(serializers.ModelSerializer):
+
+ learning_unit = LearningUnitSerializer(many=True)
+
+ class Meta:
+ model = LearningModule
+ fields = '__all__'
+
+
+class CourseSerializer(serializers.ModelSerializer):
+
+ learning_module = LearningModuleSerializer(many=True)
+
+ class Meta:
+ model = Course
+ exclude = (
+ 'teachers',
+ 'rejected',
+ 'requests',
+ 'students',
+ 'grading_system',
+ 'view_grade',
+ )