我是django的新手,我在显示平均时间时遇到问题 我的数据库模型是
from django.db import models
class Employee(models.Model):
class Meta:
db_table = 'Employee'
emp_id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=100, blank=True, null=True)
department_id = models.IntegerField(blank=True, null=True)
position = models.CharField(max_length=100, blank=True, null=True)
def __str__(self):
return self.name
class AttendanceRecord(models.Model):
class Meta:
db_table = 'AttendanceRecord'
emp_id = models.ForeignKey(Employee, on_delete=models.CASCADE)
# emp_id = models.CharField(max_length=100, blank=True, null=True)
date = models.CharField(max_length=100, blank=True, null=True)
miti = models.CharField(max_length=100, blank=True, null=True)
day = models.CharField(max_length=100, blank=True, null=True)
in_time = models.CharField(max_length=100, blank=True, null=True)
out_time = models.CharField(max_length=100, blank=True, null=True)
punch_count = models.IntegerField(blank=True, null=True)
time_spent = models.FloatField(blank=True, null=True)
difference_time = models.FloatField(blank=True, null=True)
def __str__(self):
return self.emp_id.name
class Department:
class Meta:
db_table = 'Department'
department_id = models.IntegerField(primary_key=True)
staff_count= models.IntegerField()
我的报告视图是: 我想平均in_time,以便我可以平均它并显示在报告模板中。我不知道怎么办。
from attendance.models import AttendanceRecord
class Report:
def get_all_employee_data(from_date, to_date):
all_employee_list = AttendanceRecord.objects.filter(miti__gt=from_date, miti__lt=to_date).order_by(
'-miti')
return all_employee_list
def get_specific_emp_data(from_date, to_date, e_id):
specific_employee_list = AttendanceRecord.objects.filter(miti__gt=from_date, miti__lt=to_date,
emp_id=e_id).order_by('-miti')
return specific_employee_list
我的测试数据如下所示 TEST DATA