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", "visible", "category", "created_by", "completions", "total_percentage_scored_by_users", "total_rating", "avg_rating", "rates_amount", "difficulty_label", "avg_difficulty" ) def create(self, validated_data): instance = Test.objects.create( **validated_data ) return instance