【发布时间】:2021-08-27 06:22:46
【问题描述】:
我是 django 的新手,我正在帮助创建一个网站,现在他们要求显示一个特定的数字,而我尝试使用 for 循环,它是这样的:
class Students(models.Model):
...
section = (('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'))
BlockNumber = models.CharField(max_length=10, choices=section)
现在我要做的是计算学生模型类中的每个部分选择。 我尝试使用下面的代码来计算每个选择:
def yearCount(request):
year = Students.objects.all(Count('year'))
blocks = Students.onjects.all(Count('section'))
context = {'year': year,'blocks': blocks}
return render(request, './chairperson/students/student_bsit1.html', context)
任何帮助将不胜感激,谢谢。
【问题讨论】:
-
count each section choice in the Students model class你能详细说明一下吗...??您期望的样本结果是什么......?? -
您是否要计算以 1 作为他们的部分、2 作为他们的部分等等的学生数量?如果是这样,请看这里:stackoverflow.com/questions/30752268/…
标签: django django-models