SOITA/trials/serializers.py

29 lines
671 B
Python

from rest_framework import serializers
from questions.serializers import QuestionSerializer
from trials.models import Test
from categories.serializers import CategorySerializer
class TestSerializer(serializers.ModelSerializer):
questions = QuestionSerializer(many=True, required=False)
#category = CategorySerializer(required=False)
class Meta:
model = Test
fields = (
"id",
"name",
"passing_score",
"questions",
"category",
)
def create(self, validated_data):
instance = Test.objects.create(
**validated_data
)
return instance