我有一個非常簡單的查詢設置和相關的通用視圖:下一頁鏈接/通用視圖
f_detail = {
'queryset': Foto.objects.all(),
'template_name': 'foto_dettaglio.html',
"template_object_name" : "foto",
}
urlpatterns = patterns('',
# This very include
(r'^foto/(?P<object_id>\d+)/$', list_detail.object_detail, f_detail,),
)
只是用於生成照片的詳細信息頁面模板:所以沒有看法。
是否有簡單的方法可以鏈接到以前的|模板中的下一個元素 沒有手動編碼視圖?
財產以後像:
{% if foto.next_item %}
<a href="/path/foto/{{ foto.next_item.id_field }}/">Next</a>
{% endif}
Mmh的你想知道嗎?是的,您可能已經提供瞭解決方案。你只需要實現'next_item'方法。 – 2010-02-06 22:44:46
http://stackoverflow.com/questions/1931008/is-there-a-clever-way-to-get-the-previous-next-item-using-the-django-orm – shanyu 2010-02-06 23:00:35
看到:如果我沒有注意到它以及它是關於在模型中有一個DateField或DateTimeField,這不是我的情況:我想通過(比方說)id字段來命令我的查詢集結果。 是否有預配置的方式來遍歷結果集並獲取以前的|下一個項目?還是應該設計自己的視圖並編寫_get_(next | previous)_item函數? – eaman 2010-02-07 01:55:27