我有一个包含以下字段的模型:“日期”,“员工”和“计划时间”。每位员工都有不同日期的计划时间。
我正在尝试构建我的模板,其中员工按行列出,其计划时间列在正确的相应日期下的列中。
我目前正在过滤两个日期。一名员工有时间第二次约会,但不是最近的约会。我希望他的时间在第二个日期正确列出,但目前它正在当前日期显示。查看追踪1小时:http://i.imgur.com/O4sake8.png
我的观点:
def DesignHubR(request):
emp3_list = Projectsummaryplannedhours.objects.values_list('displayval', 'employeename').\
filter(businessunit='a').filter(billinggroup__startswith='PLS - Project').filter(Q(displayval=sunday2)|Q(displayval=sunday)).\
annotate(plannedhours__sum=Sum('plannedhours'))
emp3 = map(lambda x: {'date': x[0], 'employee_name': x[1], 'planned_hours': x[2]}, emp3_list)
context = {'sunday': sunday, 'emp2': emp2, 'sunday2': sunday2, 'emp3': emp3}
return render(request,'department_hub_ple.html', context)
我的模板:
{% regroup emp3 by employee_name as emp9 %}
{% for employee_name in emp9 %}
<!--Job-->
<div class="table-row table-job-column employee-row">{{employee_name.grouper}}</div>
{% regroup employee_name.list by date|date as date_list %}
{% for y in date_list %}
<div class="table-row table-fr-column">{{y.list.0.planned_hours|default:"0"}}</div>
<div class="table-row table-fr-column">{{y.list.1.planned_hours|default:"0"}}</div>
{% endfor %}{% endfor %}
emp3_list数据:
[{'date': 'W/E 6/18/17', 'planned_hours': Decimal('45.00000'), 'employee_name': 'Waylan'}, {'date': 'W/E 6/25/17', 'planned_hours': Decimal('45.00000'), 'employee_name': 'Waylan'}, {'date': 'W/E 6/18/17', 'planned_hours': Decimal('17.00000'), 'employee_name': 'Michael'}, {'date': 'W/E 6/25/17', 'planned_hours': Decimal('13.00000'), 'employee_name': 'Michael'}, {'date': 'W/E 6/25/17', 'planned_hours': Decimal('1.00000'), 'employee_name': 'Chase'}, {'date': 'W/E 6/18/17', 'planned_hours': Decimal('27.00000'), 'employee_name': 'Bert'}, {'date': 'W/E 6/25/17', 'planned_hours': Decimal('29.00000'), 'employee_name': 'Bert'}]
型号:
class Projectsummaryplannedhours(models.Model):
number = models.CharField(db_column='Number', max_length=50, blank=True, null=True) # Field name made lowercase.
description = models.CharField(db_column='Description', max_length=100, blank=True, null=True) # Field name made lowercase.
clientname = models.CharField(db_column='ClientName', max_length=100, blank=True, null=True) # Field name made lowercase.
department = models.CharField(db_column='Department', max_length=50, blank=True, null=True) # Field name made lowercase.
billinggroup = models.CharField(db_column='BillingGroup', max_length=50, blank=True, null=True) # Field name made lowercase.
businessunit = models.CharField(db_column='BusinessUnit', max_length=50, blank=True, null=True) # Field name made lowercase.
employeename = models.CharField(db_column='EmployeeName', max_length=50, blank=True, null=True) # Field name made lowercase.
displayval = models.CharField(db_column='DisplayVal', max_length=50, blank=True, null=True) # Field name made lowercase.
startofweek = models.DateTimeField(db_column='StartOfWeek', blank=True, null=True) # Field name made lowercase.
endofweek = models.DateTimeField(db_column='EndOfWeek', blank=True, null=True) # Field name made lowercase.
plannedhours = models.DecimalField(db_column='PlannedHours', max_digits=10, decimal_places=5, blank=True, null=True) # Field name made lowercase.
rateschedule = models.CharField(db_column='RateSchedule', max_length=50, blank=True, null=True) # Field name made lowercase.
classification = models.CharField(db_column='Classification', max_length=50, blank=True, null=True) # Field name made lowercase.
dollarsforecast = models.DecimalField(db_column='DollarsForecast', max_digits=10, decimal_places=5, blank=True, null=True) # Field name made lowercase.
deleted = models.NullBooleanField(db_column='Deleted') # Field name made lowercase.
datelastmodified = models.DateTimeField(db_column='DateLastModified', blank=True, null=True) # Field name made lowercase.
datecreated = models.DateTimeField(db_column='DateCreated', blank=True, null=True) # Field name made lowercase.
答案 0 :(得分:0)
这可以是一个解决方案: {%for date in date_list%} if(y.list.0.date == current_date){ {{y.list.0.planned_hours |默认: “0”}} {{y.list.1.planned_hours |默认: “0”}} {{y.list.2.planned_hours |默认: “0”}} }其他{ ----- {{y.list.0.planned_hours |默认: “0”}} {{y.list.1.planned_hours |默认: “0”}} } {%endfor%} {%endfor%}