I am trying to build a grading system. I have a class called Score
which lists all the scores of students.
class Score(Base):
student = models.ForeignKey(Usr, limit_choices_to={'user_type': 'Student'}, related_name='scored')
subject = models.ForeignKey(Subject)
teacher = models.ForeignKey(Usr, limit_choices_to={'user_type': 'Teacher'}, related_name='marked')
exam = models.CharField(max_length=50)
exam_date = models.DateField()
score = models.IntegerField()
out_of = models.IntegerField()
The view currently passes two objects, student_list
and subject_list
, which carries the number of student in a particular class, and the number of subjects that the logged in teacher takes. This will allow him to choose which subject he is marking for that particular group of students.
def Edit(request, pk):
this_klass = Klass.objects.get(id=pk)
student_list = this_klass.kara_pore.all()
subject_list = request.user.teaches.subject.all
return render(request, "grades/edit.html", {'student_list': student_list, 'subject_list': subject_list})
The template displays a table, where the farthest left column has the student list, and then the next column has textfields for submitting their scores. I have named the textfields as the id
of the corresponding student, hoping that would help me to reference them while saving the scores.
{% extends "base.html" %}
{% block body %}
<form method="POST" action="process/"> {% csrf_token %}
<select name="sub">
{% for subject in subject_list %}
<option value="{{ subject }}">{{ subject }}</option>
{% endfor %}
</select>
<br/>
{% for student in student_list %}
{{ student }}<input type="text" name="{{ student.student_id}}"/> <br/>
{% endfor %}
<input type="submit" value="Submit"/>
</form>
{% endblock %}
I currently have no idea how I can process the entry of the scores and save them in the Score
table in reference to specific students. Till now I have only saved one row in Django. More specifically, am I saving the data the wrong way? Do I have to use arrays for this type of problems?