class Grade(models.Model):
""" Баллы """
teacher = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Учитель')
grades = models.IntegerField(verbose_name='Баллы>', default=0)
key = models.ForeignKey(Lecture, verbose_name='За занятие', on_delete=models.CASCADE)
key_to_student = models.ManyToManyField(Students, verbose_name='Студентам')
class Meta:
verbose_name = 'Баллы'
verbose_name_plural = 'Баллы'
def __str__(self):
return """ Баллы: {}, за занятие: {}""".format(self.grades, self.key.title)
<tbody>
{% for row in table %}
{% for student in row.key_to_student.all %}
<tr>
<td>{{ student.full_name }}</td>
<td>{{ row.key.title }}</td>
<td>{{ row.teacher.get_full_name }}</td>
{% if row.grades == 0 %}
<td>Пропуск</td>
{% else %}
<td id="value">{{ row.grades }}</td>
{% endif %}
<td>
*<script type="text/javascript">
let sum = 0;
for (let i = 1; i <= n; i++) {
sum += document.getElementById("value");
document.write(sum);
</script>*
</td>
<td>{{ row.key.date }}</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>