我有一個「模板」中呈現的「promotion」事件的queryset。這些促銷活動中的每一個還有一個或多個約會。我想要做的是顯示第一次和最後一次約會的日期。「Last」標記不起作用
到目前爲止,使用「第一」標籤的作品。然而,使用「最後一個」標籤的原因:
TemplateSyntaxError異常值: 捕獲的異常而呈現:不支持 負索引。
這裏是模板腳本
{% for promotion in promotions%}
{% with promotion.appointment_set.all as appointments %}
{% with appointments|first as first_ap %}
{{ first_ap.date|date }}
{% endwith %}
{% with appointments|last as last_ap %}
{{ last_ap.date|date }}
{% endwith %}
{% endwith %}
{% endfor %}
我在做什麼錯在這裏?
謝謝丹尼爾。我實際上可能會使用這個,因爲我需要應用程序中其他地方的功能。但是,是的,我可以看到我可能會在其他地方使用Manoj的建議。 – alj 2010-09-10 15:34:56