Skip to content

Commit

Permalink
Add courses where user is teacher to api
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelGusse authored and ihalaij1 committed Mar 5, 2024
1 parent b31e686 commit 8868d57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions userprofile/api/full_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ class UserSerializer(UserBriefSerializer):
last_name = serializers.CharField(source='user.last_name')
email = serializers.CharField(source='user.email')
enrolled_courses = SerializerMethodField()
staff_courses = SerializerMethodField()

class Meta(UserBriefSerializer.Meta):
fields = (
'enrolled_courses',
'staff_courses',
'student_id',
'full_name',
'first_name',
Expand All @@ -36,3 +38,8 @@ def get_enrolled_courses(self, obj):
courses = CourseInstance.objects.get_enrolled(obj)
serializer = CourseBriefSerializer(instance=courses, many=True, context=self.context)
return serializer.data

def get_staff_courses(self, obj):
staff_courses = CourseInstance.objects.get_teaching(obj)
serializer = CourseBriefSerializer(instance=staff_courses, many=True, context=self.context)
return serializer.data
1 change: 1 addition & 0 deletions userprofile/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def test_get_userdetail(self):
'student_id':'12345X',
'is_external': False,
'enrolled_courses': [],
'staff_courses': [],
'full_name':'Superb Student',
'first_name':'Superb',
'last_name':'Student',
Expand Down

0 comments on commit 8868d57

Please sign in to comment.