Add separate session serializer for course list

This commit is contained in:
Tanner Collin 2020-01-15 01:31:41 +00:00
parent 4e82f13f74
commit a178516811
2 changed files with 10 additions and 2 deletions

View File

@ -229,6 +229,11 @@ class SessionSerializer(serializers.ModelSerializer):
def get_student_count(self, obj): def get_student_count(self, obj):
return len(obj.students.all()) return len(obj.students.all())
class SessionListSerializer(SessionSerializer):
class Meta:
model = models.Session
fields = '__all__'
class CourseSerializer(serializers.ModelSerializer): class CourseSerializer(serializers.ModelSerializer):
class Meta: class Meta:
@ -236,12 +241,11 @@ class CourseSerializer(serializers.ModelSerializer):
fields = '__all__' fields = '__all__'
class CourseDetailSerializer(serializers.ModelSerializer): class CourseDetailSerializer(serializers.ModelSerializer):
sessions = SessionSerializer(many=True) sessions = SessionListSerializer(many=True)
class Meta: class Meta:
model = models.Course model = models.Course
fields = '__all__' fields = '__all__'
depth = 1
class AdminCourseSerializer(serializers.ModelSerializer): class AdminCourseSerializer(serializers.ModelSerializer):
class Meta: class Meta:

View File

@ -21,6 +21,10 @@ class IsOwnerOrAdmin(BasePermission):
def has_object_permission(self, request, view, obj): def has_object_permission(self, request, view, obj):
return obj.user == request.user or is_admin_director(request.user) return obj.user == request.user or is_admin_director(request.user)
class IsInstructor(BasePermission):
def has_object_permission(self, request, view, obj):
return user.member.is_instructor
class RetrieveUpdateViewSet( class RetrieveUpdateViewSet(
viewsets.GenericViewSet, viewsets.GenericViewSet,