Nested Regroups - Django

后端 未结 1 946
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 17:48

I have a model with the following fields: \"Date\", \"Employee\", and \"Planned Hours\". Each employee has various planned hours for various dates.

I\'m attempting to s

相关标签:
1条回答
  • 2021-01-26 18:00

    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.

    The View:

    Class EmployeeTimeSheetView(ListView):
        model = Projectsummaryplannedhours
        template_name = "department_hub_ple.html"
    
        def get_queryset(self): 
           return Projectsummaryplannedhours.objects.all().order_by('-date')
    

    The Template:

    {% 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 %}
    

    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.

    0 讨论(0)
提交回复
热议问题