且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

嵌套重组-Django

更新时间:2023-08-18 16:48:16

您是否尝试过重新组合?您还尝试过基于类的视图吗?它们对于快速生成代码非常有用。

Have you tried to regroup your regroup? Also have you tried ClassBased Views at all? They are really useful for quick code generation. Something like the following.

视图:

Class EmployeeTimeSheetView(ListView):
    model = Projectsummaryplannedhours
    template_name = "department_hub_ple.html"

    def get_queryset(self): 
       return Projectsummaryplannedhours.objects.all().order_by('-date')

模板:

{% regroup object_list by date|date:"m/d/Y" as date_list %}
    {% for date in date_list %}
     ###html code {{ date.grouper }}
    {% regroup date.list by employee as employee_list %}
        {% for employee in employee_list %}
            ###html code {{ employee.grouper }}
        {% endfor %}
     {% endfor %}

这将使您可以建立一个以日期为列标题的表,然后在下面的oder中列出其计划工时。可能需要进行一些调整才能显示所需的信息,而这可能只是您重新分组依据的字段。

This should allow you to build a table with dates as the column headers and then list the employees in oder below with their planned hours. It might require a little tweaking to get it to display the information you want and that might just comedown to which fields you regroup by.

我使用这种重新分组的方法相关的项目按月,然后按周。

I use this kind of regroup to group related items by Month then by Week.