У меня есть связанный вопрос здесь . Я просто не знаю, как получить правильные данные.
Точно так же, как на этом рисунке (для каждого учащегося, выбирая каждый балл для всех основных значений (это Демонстрация гордости… ..) ) :
Это мои views.py:
for i, mark in enumerate(request.POST.getlist('Marking')):
p = marking[int(mark)]
s = StudentBehaviorMarking(id=p)
core = corevalues[i]
cores = EducationLevelGradingBehavior(id=core)
print(s, cores)
for student in request.POST.getlist('student'):
students = StudentPeriodSummary(id=student)
V_insert_data = StudentsBehaviorGrades(
Teacher=teacher,
#Education_Levels
Students_Enrollment_Records = students,
Grading_Period = coreperiod,
Grading_Behavior = cores,
Marking = s,
)
V_insert_data.save()
И мои HTML:
<tr>
{% for corevalues in behaviorperlevels %}
<td colspan="4" style="font-size: 12px"><input type="text" value="{{corevalues.id}}" name="coredescription">{{corevalues.Grading_Behavior.GroupName}}</td>
{% endfor %}
</tr>
<tr>
<td colspan="2">Student name</td>
{% for corevalues in behaviorperlevels %}
<td colspan="4" style="font-size: 12px"><input type="text" value="{{corevalues.id}}" name="period">Q {{corevalues.Grading_Period.id}}</td>
{% endfor %}
</tr>
{% for student in Students %}
<tr>
<td colspan="2"><input type="text" value="{{student.id}}" name="student">{{student.Students_Enrollment_Records.Students_Enrollment_Records.Students_Enrollment_Records.Student_Users}}</td>
{% for corevalues in behaviorperlevels %}
<td colspan="4">
<select name="Marking">
{% for behaviors in behavior %}
<option value="{{behaviors.id}}">{{behaviors.Marking}}</option>
{% endfor %}
</select>
</td>
{% endfor %}
</tr>
{% endfor %}
Это мои models.py:
class GradingBehavior(models.Model):
Display_Sequence = models.IntegerField(null=True, blank=True)
Name = models.CharField(max_length=500, null=True, blank=True)
Description = models.CharField(max_length=500, null=True, blank=True)
GroupName = models.CharField(max_length=500, null=True, blank=True)
GroupDescription = models.CharField(max_length=500, null=True, blank=True)
//this is models corevalues
class EducationLevelGradingBehavior(models.Model):
Display_Sequence = models.IntegerField(null=True, blank=True)
GradeLevel = models.ForeignKey(EducationLevel, on_delete=models.CASCADE,
null=True, blank=True)
Grading_Behavior = models.ForeignKey(GradingBehavior, on_delete=models.CASCADE, null=True, blank=True)
Grading_Period = models.ForeignKey(gradingPeriod, on_delete=models.CASCADE, null=True, blank=True)
//this is the models where the user selecting the marks for every core values
class StudentBehaviorMarking(models.Model):
Marking = models.CharField(max_length=500, null=True, blank=True)
Non_numerical_Rating = models.CharField(max_length=500, null=True, blank=True)
//this is the model where the data saves
class StudentsBehaviorGrades(models.Model):
Teacher = models.ForeignKey(EmployeeUser, on_delete=models.CASCADE,
null=True, blank=True)
Education_Levels = models.ForeignKey(EducationLevel, on_delete=models.CASCADE, null=True, blank=True)
Students_Enrollment_Records = models.ForeignKey(StudentPeriodSummary,
on_delete=models.CASCADE, null=True)
Grading_Period = models.ForeignKey(gradingPeriod, on_delete=models.CASCADE, null=True, blank=True)
Grading_Behavior = models.ForeignKey(EducationLevelGradingBehavior, on_delete=models.CASCADE, null=True, blank=True)
Marking = models.ForeignKey(StudentBehaviorMarking,
on_delete=models.CASCADE, null=True)
Когда я пытаюсь вставить данные
это результат :
Как видите, введенные данные не соответствуют должным образом, я не получил правильное значение для каждого учащихся отметка для каждых значений ядра .