Commit 1c221fda authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Add course track to Course serializer

parent 2b488810
......@@ -7,6 +7,7 @@ from .models import (
CourseProfessor,
ProfessorMessage,
ProfessorMessageRead,
CourseTrack,
)
......@@ -31,6 +32,7 @@ class CourseSerializer(serializers.ModelSerializer):
is_user_assistant = serializers.SerializerMethodField()
is_user_coordinator = serializers.SerializerMethodField()
is_assistant_or_coordinator = serializers.SerializerMethodField()
track = serializers.SerializerMethodField()
class Meta:
model = Course
......@@ -39,7 +41,7 @@ class CourseSerializer(serializers.ModelSerializer):
"thumbnail_url", "home_thumbnail_url", "home_position",
"start_date", "home_published", "authors_names", "has_started",
"min_percent_to_complete", "is_user_assistant", "is_user_coordinator",
"is_assistant_or_coordinator", 'professors', )
"is_assistant_or_coordinator", 'professors', 'track',)
@staticmethod
def get_home_thumbnail_url(obj):
......@@ -56,6 +58,12 @@ class CourseSerializer(serializers.ModelSerializer):
def get_is_assistant_or_coordinator(self, obj):
return obj.is_assistant_or_coordinator(self.context['request'].user)
def get_track(self, obj):
course_track = CourseTrack.objects.filter(courses=obj)
if course_track:
return {'name': course_track.first().name, 'home_position': course_track.first().home_position }
return {}
def update(self, instance, validated_data):
intro_video_data = validated_data.pop('intro_video', None)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment