【问题标题】:need to calculate total time month wise in django需要在 Django 中按月计算总时间
【发布时间】:2023-01-17 14:42:31
【问题描述】:

我创建了计算总时间的函数。

def emp_attendance(request):
    attendance_list_ad = Attendance.objects.all()
    total = None
    for item in attendance_list_ad:
        if item.total_time is not None:
            if total is None:
                total = item.total_time
            else:
                total += item.total_time
    return render(request, 'employee/emp_attendance.html'{'attendance_list_ad': attendance_list_ad, 'total': 
                               total})

打印时:

出勤日期 = 2023-01-09 总时间 = 1:00:00

所以我的问题是在首页这个函数正在计算数据库中所有条目的总时间。但我想按月计算总时间,因为我们有 01 月的出勤日期。然后将计算总时间

【问题讨论】:

    标签: python django


    【解决方案1】:

    我不确定我是否完全理解你的问题。

    也许Python中的datetime模块会对你有所帮助,也许不会。

    【讨论】:

    • 我的问题是我在多个月的数据库中有条目。当我计算总时间时,它正在计算每个条目的时间,例如还包括 2 月和 3 月的条目。所以我只需要计算一月的时间
    猜你喜欢
    • 2023-03-09
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    • 1970-01-01
    相关资源
    最近更新 更多