You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
937 B

from rest_framework import serializers
from course_service.maps.models import CourseRoute, CourseMap
class CourseRouteSerializer(serializers.ModelSerializer):
maps = serializers.SerializerMethodField()
class Meta:
model = CourseRoute
fields = ('maps', 'name')
@staticmethod
def get_maps(self):
return [CourseMapSerializer(i).data for i in self.get_maps()][0]
class CourseMapSerializer(serializers.ModelSerializer):
tree = serializers.SerializerMethodField()
course_slug = serializers.SerializerMethodField()
map_name = serializers.SerializerMethodField()
class Meta:
model = CourseMap
fields = ('tree', 'course_slug', 'map_name')
@staticmethod
def get_tree(self):
return self.get_tree()
@staticmethod
def get_course_slug(self):
return self.course.slug
@staticmethod
def get_map_name(self):
return self.name