通过userid django将总和值转换为百分比 [英] convert sum value to percentage by userid django

查看:48
本文介绍了通过userid django将总和值转换为百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过用户ID 将总金额转换为百分比,但是当我尝试运行以下程序时弹出错误消息.

I'm trying to convert the total sum to a percentage by userid but an error pops up when I try to run the following program.

错误是:

未定义名称标记"

name 'mark' is not defined

下面是我的 views.py

def attStudName(request):
students = MarkAtt.objects.values('studName__VMSAcc').annotate(mark=Sum('attendance'), percentage=(F('mark')/1100) *100)
    context = {
    'students' : students,

        }
    context = {
    'students' : students,
    'ttl' : ttl
        }
    return render(request,'show-name.html',context)

设法获取值,但返回全零.这是我的数据:

Managed to get the value out but it returned all zero. Here is my data:

学生姓名|考勤标志|百分比

Student Name| Attendance Mark | Percentage

anni |800 |0

anni | 800 | 0

本尼|800 |0

推荐答案

我的答案中缺少".试试这个:

There was some '' missing in my answer. Try this:

from django.db.models import F
students = MarkAtt.objects.values('studName__VMSAcc').annotate(mark=Sum('attendance'), percentage=(F('mark') / 1100) * 100)

然后在模板中:

{% for student in students %}
    {{ student.studName__VMSAcc }}
    {{ student.mark }}
    {{ student.percentage }}
{% endfor %}

这篇关于通过userid django将总和值转换为百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆