Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在django中优雅地显示每个用户的总和_Python_Django_Django Models_Django Views - Fatal编程技术网

Python 在django中优雅地显示每个用户的总和

Python 在django中优雅地显示每个用户的总和,python,django,django-models,django-views,Python,Django,Django Models,Django Views,试图显示每个学生的最终分数。但它不只是显示sum的结果,而是显示查询集的一块:例如: Annie <QuerySet [{'studName': None, 'attendance__sum': 3}, {'studName': 1, 'attendance__sum': 2}, {'studName': 2, 'attendance__sum': 1}]> 我的模板: {% for y in mark %} {% for x in studentName %} <

试图显示每个学生的最终分数。但它不只是显示sum的结果,而是显示查询集的一块:例如:

Annie <QuerySet [{'studName': None, 'attendance__sum': 3}, {'studName': 1, 'attendance__sum': 2}, {'studName': 2, 'attendance__sum': 1}]>
我的模板:

{% for y in mark %}

{% for x in studentName %}  

 <p>{{x.studName}}</p> <p> {{mark}}</p>

 {% endfor %}
{% endfor %}  
{% for student in students %}  
    <p>{{student.studName}}</p> <p> {{ student.mark}}</p>
{% endfor %}

提前谢谢。

下面应该返回一个包含学生姓名和分数的查询集。不需要两个单独的查询

students = MarkAtt.objects.values('studName').annotate(mark=Sum('attendance'))
如果
studName
是外键,请执行此操作
.values('studName\uuu name')

然后,在您的上下文中,您可以添加:

context = {
    students = students
}
然后,您可以在模板中循环浏览
学生
,并将数据显示为:

<p>{{x.studName}}</p> <p> {{x.mark}}</p>
{{x.studName}

{{x.mark}


下面应该返回一个包含学生姓名和分数的查询集。不需要两个单独的查询

students = MarkAtt.objects.values('studName').annotate(mark=Sum('attendance'))
如果
studName
是外键,请执行此操作
.values('studName\uuu name')

然后,在您的上下文中,您可以添加:

context = {
    students = students
}
然后,您可以在模板中循环浏览
学生
,并将数据显示为:

<p>{{x.studName}}</p> <p> {{x.mark}}</p>
{{x.studName}

{{x.mark}


你把事情复杂化了。鉴于以下简单背景:

students = MarkAtt.objects.values('studName').annotate(mark=Sum('attendance'))
context = {
    'students' : students,
}
您可以在模板中执行以下操作:

{% for y in mark %}

{% for x in studentName %}  

 <p>{{x.studName}}</p> <p> {{mark}}</p>

 {% endfor %}
{% endfor %}  
{% for student in students %}  
    <p>{{student.studName}}</p> <p> {{ student.mark}}</p>
{% endfor %}
{%用于学生%}
{{student.studName}

{{student.mark}

{%endfor%}
你把事情复杂化了。鉴于以下简单背景:

students = MarkAtt.objects.values('studName').annotate(mark=Sum('attendance'))
context = {
    'students' : students,
}
您可以在模板中执行以下操作:

{% for y in mark %}

{% for x in studentName %}  

 <p>{{x.studName}}</p> <p> {{mark}}</p>

 {% endfor %}
{% endfor %}  
{% for student in students %}  
    <p>{{student.studName}}</p> <p> {{ student.mark}}</p>
{% endfor %}
{%用于学生%}
{{student.studName}

{{student.mark}

{%endfor%}
请添加型号代码您是否为“学生”型号设置了
外键
?请添加型号代码您是否为“学生”型号设置了
外键
?您好。是的,我的名字是名字列表的外键。我试图输入'studName_name',但它显示了一个错误:“无法将关键字'studName_name'解析到字段中。选项有:考勤、classGrp、classGrp_id、currentDate、id、studName、studName_id、week”我已在上面添加了我的模型使用双下划线,并指向包含学生姓名的字段。要输入{{x.studName\uuu name}还有。你知道如何将这些信息导出到excel吗?这是一个完全不同的问题,完全不是原始问题的一部分。我建议为此记录一个新问题。是的,这将是你在模板中引用字段的方式。我已记录了一个新问题。你可以看看这个问题吗?我的导出不是w目前正在工作。这是链接:您好。是的,我的studName是姓名列表的外键。我试图输入'studName\u name',但它显示了一个错误:“无法将关键字'studName\u name'解析到字段中。选项包括:考勤、classGrp、classGrp\u id、currentDate、id、studName、studName\u id、week”我已经在上面添加了我的模型,使用双下划线,并指向包含学生姓名的字段。要获得它,我需要输入{{x.studName\uuuu name}}还有。你知道如何将这些信息导出到excel吗?这是一个完全不同的问题,完全不是原始问题的一部分。我建议为此记录一个新问题。是的,这将是你在模板中引用字段的方式。我已记录了一个新问题。你可以看看这个问题吗?我的导出不是w正在工作。链接如下: