0

我的 django 模板中有这段代码:

{%for client in clients %}
    {% regroup books by com_name as com_name_list %}
       {% for com_name in com_name_list %}
            <tr>
            <td>
            <h3>{{ com_name.grouper }}</h3>
            </td>                                           
            </tr>
            {% for book in com_name.list %}
                {%if client.client.id == book.client.id %}
            <tr>
            <td></td>
            <td>
            {{book.id}}
            </td>
            <td>{{ book.created }}</td>
            <td>
            {% if client.client.b_type == 'ticketing'%}
                {{ book.date_select }}
            {% endif %}
            {% if client.client.b_type == 'hotel'%}
                {{ book.check_in }} - {{ book.check_out }}
            {% endif %}
            </td>
            <td>{{ book.last_name }}, {{ book.first_name }}</td>
            <td>{{ book.product }}</td>
            <td>{{ book.quantity }}</td>
                <td>{{ book.totalcost_rate|floatformat:2|intcomma }}</td>                                          <td>{{ book.status }} {{book.com_name}}</td>
             </tr>
            {%endif%}
        {% endfor %}
    {% endfor %}
{%endfor%}

但我想知道为什么输出是这样的:

Partner ID  Transaction Date    Booking Date              Guest Name    Product        Qty  Amount          Status
test
        2   April 19, 2012   April 1, 2012 - April 2, 2012    hjb, jbh  Dormitory Room  1   1,000.00    Complete test
        3   April 19, 2012   April 10, 2012 - April 11, 2012  KJNJK, hbk    Dormitory Room  1   1,000.00    Complete test
direct h
        4   April 19, 2012   April 19, 2012 - April 20, 2012  HBH, JGVJ Dormitory Room  1   1,000.00    Complete direct h
        5   April 19, 2012   April 9, 2012 - April 10, 2012   kjnkj, njkjn  g           1   1,000.00    Complete direct h
test
        9   April 27, 2012   May 1, 2012 - May 2, 2012    ljnd, asdf    Dormitory Room  1   1,000.00    Complete test
       10   April 27, 2012   April 27, 2012 - April 28, 2012  jhbjh, dsjg   Dormitory Room  1   1,000.00    Complete test
       11   April 28, 2012   April 9, 2012 - April 10, 2012   jnj, asjn Dormitory Room  1   1,000.00    Complete test
       12   April 28, 2012   April 11, 2012 - April 12, 2012  jnj, jjn  Dormitory Room  1   1,000.00    Complete test

我的重组不正确吗?我应该怎么做才能像这样对它进行分组。

Partner ID  Transaction Date    Booking Date              Guest Name    Product        Qty  Amount          Status
test
        2   April 19, 2012   April 1, 2012 - April 2, 2012    hjb, jbh  Dormitory Room  1   1,000.00    Complete test
        3   April 19, 2012   April 10, 2012 - April 11, 2012  KJNJK, hbk    Dormitory Room  1   1,000.00    Complete test
        9   April 27, 2012   May 1, 2012 - May 2, 2012    ljnd, asdf    Dormitory Room  1   1,000.00    Complete test
       10   April 27, 2012   April 27, 2012 - April 28, 2012  jhbjh, dsjg   Dormitory Room  1   1,000.00    Complete test
       11   April 28, 2012   April 9, 2012 - April 10, 2012   jnj, asjn Dormitory Room  1   1,000.00    Complete test
       12   April 28, 2012   April 11, 2012 - April 12, 2012  jnj, jjn  Dormitory Room  1   1,000.00    Complete test

direct h
        4   April 19, 2012   April 19, 2012 - April 20, 2012  HBH, JGVJ Dormitory Room  1   1,000.00    Complete direct h
        5   April 19, 2012   April 9, 2012 - April 10, 2012   kjnkj, njkjn  g           1   1,000.00    Complete direct h

任何人都可以在我的情况下帮助我吗?提前致谢...

4

1 回答 1

2

regroup 不会对其输入进行排序。在将列表传递给重组之前,您必须按 com_name 对列表进行排序。文档对此进行了解释并举了一个例子。

于 2012-04-28T09:01:16.830 回答