Add separate session serializer for course list
This commit is contained in:
parent
4e82f13f74
commit
a178516811
|
@ -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:
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user