vbv/server/vbv_lernwelt/competence/serializers.py

36 lines
1.3 KiB
Python

from rest_framework import serializers
from vbv_lernwelt.competence.models import PerformanceCriteria
from vbv_lernwelt.course.serializers import CourseCategorySerializer
from vbv_lernwelt.learnpath.models import LearningUnit
from vbv_lernwelt.learnpath.serializer_helpers import get_it_serializer_class
class PerformanceCriteriaSerializer(get_it_serializer_class(PerformanceCriteria, [
'id', 'title', 'slug', 'type', 'translation_key',
'competence_id', 'learning_unit', 'circle', 'course_category',
])):
learning_unit = serializers.SerializerMethodField()
circle = serializers.SerializerMethodField()
course_category = serializers.SerializerMethodField()
def get_learning_unit(self, obj):
learning_unit_serializer = get_it_serializer_class(LearningUnit, [
'id', 'title', 'slug', 'type', 'translation_key',
])
return learning_unit_serializer(obj.learning_unit).data
def get_circle(self, obj):
return obj.learning_unit.get_parent().specific.title
def get_course_category(self, obj):
if obj.learning_unit:
return CourseCategorySerializer(obj.learning_unit.course_category).data
return None
class PerformanceCriteriaLearningPathSerializer(get_it_serializer_class(PerformanceCriteria, [
'id', 'title', 'slug', 'type', 'translation_key', 'competence_id',
])):
pass