# coding=utf-8

from rest_framework import serializers
from .models import ErrorBook
from apps.examination.examquestion.serializers import ExamQuestionSimpleSerializer
from apps.examination.exam.serializers import ExamAnswerLogSimpleSerializer


class ErrorBookSerializer(serializers.ModelSerializer):
    question = serializers.SerializerMethodField()
    answer = serializers.SerializerMethodField()
    exam_name = serializers.CharField(source='last_answer_log.main.exampaper.name', read_only=True)

    class Meta:
        model = ErrorBook
        fields = ('last_time', 'wrong_count', 'exam_name', 'question', 'answer', )

    def get_question(self, obj):
        return ExamQuestionSimpleSerializer(obj.question).data

    def get_answer(self, obj):
        return ExamAnswerLogSimpleSerializer(obj.last_answer_log).data
