2021-12-05 13:50:34 +01:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
from questions.serializers import QuestionSerializer
|
|
|
|
from trials.models import Test
|
2021-12-12 11:35:35 +01:00
|
|
|
from categories.serializers import CategorySerializer
|
2021-12-05 13:50:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
questions = QuestionSerializer(many=True, required=False)
|
2022-01-08 22:15:30 +01:00
|
|
|
#category = CategorySerializer(required=False)
|
2021-12-05 13:50:34 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Test
|
|
|
|
fields = (
|
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"passing_score",
|
2021-12-12 11:35:35 +01:00
|
|
|
"questions",
|
2022-04-09 13:02:21 +02:00
|
|
|
"visible",
|
2021-12-12 11:35:35 +01:00
|
|
|
"category",
|
2022-05-15 16:01:52 +02:00
|
|
|
"created_by",
|
|
|
|
"completions",
|
|
|
|
"total_percentage_scored_by_users",
|
|
|
|
"total_rating",
|
|
|
|
"avg_rating",
|
|
|
|
"rates_amount",
|
|
|
|
"difficulty_label",
|
|
|
|
"avg_difficulty"
|
2021-12-05 13:50:34 +01:00
|
|
|
)
|
2021-12-12 11:35:35 +01:00
|
|
|
|
|
|
|
def create(self, validated_data):
|
|
|
|
instance = Test.objects.create(
|
|
|
|
**validated_data
|
|
|
|
)
|
|
|
|
return instance
|
|
|
|
|