Skip to content
Snippets Groups Projects
Commit 7e9264d1 authored by Jakob Dieterle's avatar Jakob Dieterle Committed by Jakob Dieterle
Browse files

added new many-to-many field and wrapper class

parent c2ca207b
No related branches found
No related tags found
1 merge request!244Resolve "Make exam a many to many field on StudentInfo model"
......@@ -26,15 +26,26 @@ def random_matrikel_no() -> str:
return str(10_000_000 + randrange(90_000_000))
<<<<<<< HEAD
class ExamInfo(models.Model):
exam = models.ForeignKey(ExamType,
on_delete=models.CASCADE,
related_name='exam_infos',
=======
class StudentsExam(models.Model):
exam = models.ForeignKey('ExamType',
on_delete=models.CASCADE,
related_name='exam',
>>>>>>> added new many-to-many field and wrapper class
null=False)
student = models.ForeignKey('StudentInfo',
on_delete=models.CASCADE,
<<<<<<< HEAD
related_name='exams',
=======
related_name='students',
>>>>>>> added new many-to-many field and wrapper class
null=False)
total_score = models.PositiveIntegerField(default=0)
......@@ -72,7 +83,11 @@ class StudentInfo(models.Model):
associated user model.
Attributes:
<<<<<<< HEAD
exams (ManyToManyField):
=======
exam (ManyToManyField):
>>>>>>> added new many-to-many field and wrapper class
Module the student wants te be graded in, or different exercise
assignments for one module.
......@@ -90,14 +105,54 @@ class StudentInfo(models.Model):
max_length=30,
default=random_matrikel_no)
<<<<<<< HEAD
=======
exams = models.ManyToManyField(StudentsExam,
blank=True,
related_name='exams',
)
>>>>>>> added new many-to-many field and wrapper class
user = models.OneToOneField(get_user_model(),
on_delete=models.CASCADE,
related_name='student')
def add_exam(self, exam):
<<<<<<< HEAD
exam_info = ExamInfo(exam=exam, student=self)
exam_info.save()
self.exams.add(exam_info)
=======
students_exam = StudentsExam()
students_exam.exam = exam
students_exam.student = self
self.exams.add(students_exam)
@classmethod
def get_annotated_score_submission_list(cls) -> QuerySet:
"""Can be used to quickly annotate a user with the necessary
information on the overall score of a student and if he does not need
any more correction.
A student is done if
* module type was pass_only and student has enough points
* every submission got accepted feedback
Returns
-------
QuerySet
the annotated QuerySet as described above.
"""
return cls.objects.annotate(
overall_score=Coalesce(Sum('submissions__feedback__score'),
Value(0)),
).annotate(
done=Case(
When(exam__pass_score__lt=F('overall_score'), then=Value(1)),
default=Value(0),
output_field=BooleanField()
)
).order_by('user__username')
>>>>>>> added new many-to-many field and wrapper class
def disable(self):
"""The student won't be able to login in anymore, but his current
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment