重新组合django模板

时间:2012-04-28 06:19:52

标签: django django-templates

我的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
在我的情况下,任何人都可以帮助我吗?提前谢谢......

1 个答案:

答案 0 :(得分:2)

重新组合不会对其输入进行排序。在将其传递给重新组合之前,您必须按com_name对列表进行排序。 The documentation解释了这一点并举了一个例子。