SOITA/trials/serializers.py

30 lines
694 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)
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",
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