Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
grady
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Maximilian Michal
grady
Commits
7e9264d1
Commit
7e9264d1
authored
4 years ago
by
Jakob Dieterle
Committed by
Jakob Dieterle
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
added new many-to-many field and wrapper class
parent
c2ca207b
No related branches found
No related tags found
1 merge request
!244
Resolve "Make exam a many to many field on StudentInfo model"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/models/student_info.py
+55
-0
55 additions, 0 deletions
core/models/student_info.py
with
55 additions
and
0 deletions
core/models/student_info.py
+
55
−
0
View file @
7e9264d1
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment