SOITA/trials/serializers.py

29 lines
670 B
Python
Raw Normal View History

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)
2021-12-12 11:35:35 +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",
"category",
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