i hope the title is enough to know what is my problem
This is my code in html
when I tried to save this to my database only the "6" is save just like in the picture
I use jquery to generate the date and textbox to input the grade
this is my html
<table id="blacklistgrid" border="2px">
<tr>
<th id="th">Students Name</th>
<th data-id='headers' id='header'>Average</th>
</tr>
{% for student in teacherStudents %}
<tr class="tr2">
<td class="td" ><input type="text" name="students" value="{{student.id}}" id="student" >{{student.Students_Enrollment_Records.Student_Users}}</td>
<td data-id='row' id="ans"><input type='number' class='averages' readonly/></td>
</tr>
{% endfor %}
</table>
<script>
var counter = 0;
function doTheInsert(){
let header=$("tr#tr"); // same as $.find("tr[id='tr2']")
$('#th').after("<th data-id='headers' id='header'><input type='date' name='date'></th>");
var rows=$(".tr2");
$("<td data-id='row' ><input type='number' name='gradeko' class='average' /></td>").insertAfter(".td");
counter++;
}
</script>
this is my views.py
for gradeko in request.POST.get('gradeko'):
pass
for students in request.POST.getlist('students'):
studentss = StudentsEnrolledSubject(id=students)
date = request.POST.getlist('date')
V_insert_data = studentsEnrolledSubjectsGrade(
Teacher=teacher,
Students_Enrollment_Records=studentss,
Date=date,
Grade=gradeko
)
V_insert_data.save()
this is my model.py
class studentsEnrolledSubjectsGrade(models.Model):
Teacher = models.ForeignKey(EmployeeUser, related_name='+', on_delete=models.CASCADE,
null=True,blank=True)
Subjects = models.ForeignKey(Subject, related_name='+', on_delete=models.CASCADE, null=True)
Students_Enrollment_Records = models.ForeignKey(StudentsEnrolledSubject, related_name='+',on_delete=models.CASCADE, null=True)
Grading_Categories = models.ForeignKey(gradingCategories, related_name='+', on_delete=models.CASCADE,
null=True,blank=True)
Date = models.DateField(null=True, blank=True)
Grade = models.FloatField(null=True, blank=True)
what i tried
global gradekos, dates
for gradeko in request.POST.getlist('gradeko'):
gradekos = gradeko
pass
print(gradekos)
for date in request.POST.getlist('date'):
dates = date
pass
for students in request.POST.getlist('students'):
studentss = StudentsEnrolledSubject(id=students)
#date = request.POST.get('date')
V_insert_data = studentsEnrolledSubjectsGrade(
Teacher=teacher,
Students_Enrollment_Records=studentss,
Date=dates,
Grade=gradekos
)
V_insert_data.save()
UPDATE when i tried two dates, only 1 date save in the database
for example
this is what I want result
this is the actual result