22 lines
767 B
Python
22 lines
767 B
Python
from rest_framework import serializers
|
|
|
|
from vbv_lernwelt.learnpath.models import Circle, LearningPath
|
|
from vbv_lernwelt.learnpath.serializer_helpers import get_it_serializer_class, _get_children
|
|
|
|
|
|
class LearningPathSerializer(get_it_serializer_class(LearningPath, [])):
|
|
children = serializers.SerializerMethodField()
|
|
|
|
meta_fields = []
|
|
|
|
def get_children(self, obj):
|
|
descendants = [p for p in obj.get_descendants().specific()]
|
|
return [c.specific.get_serializer_class()(c.specific, descendants=descendants).data for c in _get_children(descendants, obj)]
|
|
|
|
def get_meta_label(self, obj):
|
|
return obj._meta.label
|
|
|
|
class Meta:
|
|
model = Circle
|
|
fields = ['id', 'title', 'slug', 'type', 'translation_key', 'children']
|