Commit 6bb0a42e authored by Laury Bueno's avatar Laury Bueno
Browse files

[Classes] Only valid students must be listed

parent c3bd363e
......@@ -58,5 +58,9 @@ class Class(models.Model):
@property
def get_students(self):
return self.course.course_students.filter(
user__in=self.students.all(),
user__in=self.students.all(), user__is_active=True
).select_related('user').order_by('user__first_name')
@property
def valid_students(self):
return self.students.filter(is_active=True)
......@@ -17,6 +17,10 @@ from .models import Class
class BasicClassSerializer(serializers.ModelSerializer):
assistants = SimpleUserSerializer(read_only=True, many=True)
students = serializers.SerializerMethodField()
def get_students(self, obj):
return obj.valid_students.values_list('id', flat=True)
class Meta:
model = Class
......@@ -35,7 +39,7 @@ class CourseStudentClassSerializer(serializers.ModelSerializer):
class ClassSerializer(WorkspaceBaseSerializerMixin, serializers.ModelSerializer):
enrolled_students = CourseStudentClassSerializer(source='get_students', many=True, read_only=True)
students_details = SimpleUserSerializer(source='students', many=True, read_only=True)
students_details = SimpleUserSerializer(source='valid_students', many=True, read_only=True)
processes = CertificationProcessSerializer(read_only=True, many=True)
evaluations = EvaluationSerializer(read_only=True, many=True)
course = BasicCourseSerializer(read_only=True)
......
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