from rest_framework import serializers

from ct.models import Response


class ResponseSerializer(serializers.HyperlinkedModelSerializer):
    author_id = serializers.SerializerMethodField()
    lti_identity = serializers.SerializerMethodField()
    unitLesson_id = serializers.SerializerMethodField()
    unit_id = serializers.SerializerMethodField()

    class Meta:
        model = Response
        fields = (
            'id',
            'author_id',
            'lti_identity',
            'text',
            'confidence',
            'selfeval',
            'status',
            'unitLesson_id',
            'unit_id',
        )

    def get_author_id(self, obj):
        """
        Returning author id.
        """
        return obj.author.id

    def get_lti_identity(self, obj):
        """
        Returning LTI user_id.
        """
        lti_user = obj.author.lti_auth.first()
        if lti_user:
            return lti_user.user_id

    def get_unitLesson_id(self, obj):
        """
        Returning UnitLesson id.
        """
        return obj.unitLesson.id

    def get_unit_id(self, obj):
        """
        Returning Unit id.
        """
        return obj.unitLesson.unit.id

@@ -180,24 +180,78 @@
 thodField()%0A
+    author_name = serializers.SerializerMethodField()%0A
     lti_iden
@@ -285,32 +285,32 @@
 erMethodField()%0A
-
     unitLesson_i
@@ -499,24 +499,51 @@
 author_id',%0A
+            'author_name',%0A
             
@@ -792,32 +792,32 @@
 id.%0A        %22%22%22%0A
-
         return o
@@ -826,24 +826,238 @@
 .author.id%0A%0A
+    def get_author_name(self, obj):%0A        %22%22%22%0A        Returning author name.%0A        %22%22%22%0A        name = obj.author.get_full_name()%0A        if not name:%0A            name = obj.author.username%0A        return name%0A%0A
     def get_

add Django fill name or username for result