0

li タグに入る出力を最後の 2 つの項目に制限するにはどうすればよいですか? これが私がこれまでに持っているものです:

{% regroup backups by dataset as dataset_list %}
{% for dataset in dataset_list %}

<h2>{{ dataset.grouper }}</h2>

<ul>
     {% for item in dataset.list %}
        <li>
            {% if item.state = "FAILED" %}<span class="icon-cross red"> {{ item.snapshot_name }} took {{ item.start_time|timesince:item.stop_time }} to transfer {{ item.transfer_size }} and <span class="red">{{ item.state }}</span>
     {% else %}
     <span class="icon-tick green"> {{ item.snapshot_name }} took {{ item.start_time|timesince:item.stop_time }} to transfer {{ item.transfer_size }}
            {% endif %}
       </li>
    {% endfor %}
    </ul>

次のような出力が生成されます。

pool-test/data

    zfs-auto-snap_weekly-2013-01-06-0647 took 2 hours, 43 minutes to transfer 249GB
    zfs-auto-snap_weekly-2013-01-13-0647 took 0 minutes to transfer 29.6KB
    zfs-auto-snap_weekly-2013-01-20-0647 took 0 minutes to transfer 3.23KB
    zfs-auto-snap_weekly-2013-01-27-0647 took 0 minutes to transfer 312B
    zfs-auto-snap_weekly-2013-02-03-0647 took 0 minutes to transfer 312B

pool-test2/data

    zfs-auto-snap_weekly-2012-12-16-0647 took 13 minutes to transfer 35.9GB
    zfs-auto-snap_weekly-2012-12-23-0647 took 0 minutes to transfer 6.16MB
    zfs-auto-snap_weekly-2013-01-06-0647 took 0 minutes to transfer 22.4MB
    zfs-auto-snap_weekly-2013-01-13-0647 took 0 minutes to transfer 20.7MB
    zfs-auto-snap_weekly-2013-01-20-0647 took 0 minutes to transfer 19.1MB
    zfs-auto-snap_weekly-2013-01-27-0647 took 0 minutes to transfer 17.7MB
    zfs-auto-snap_weekly-2013-02-03-0647 took 0 minutes to transfer 10.2MB

私はそれが次のように見えるようにしたい:

    pool-test/data

        zfs-auto-snap_weekly-2013-01-27-0647 took 0 minutes to transfer 312B
        zfs-auto-snap_weekly-2013-02-03-0647 took 0 minutes to transfer 312B

    pool-test2/data

        zfs-auto-snap_weekly-2013-01-27-0647 took 0 minutes to transfer 17.7MB
        zfs-auto-snap_weekly-2013-02-03-0647 took 0 minutes to transfer 10.2MB
4

1 に答える 1

1

スライス フィルターを使用します。

{% for item in dataset.list|slice:"-2:" %}

于 2013-02-07T19:55:49.677 に答える