我有模板有許多選項卡(jQuery用戶界面):在Django模板的jQuery UI選項卡
<div>
Satus: <span id="status_value"> {{ purchase.get_status_display }}</span>
Owner: <span id="admin_value"> {{ purchase.owner }}</span>
</div>
<div class="tabs">
<div class="tabs-navigation">
<ul>
<li><a href="{% url purchase_info_tab %}">Purchase description</a></li>
<li><a href="{% url purchase_catalog %}">Purchase catalog</a></li>
</ul>
</div>
</div>
這是view.py,首先我主要呈現模板,比使用AJAX渲染選項卡,在這種情況下purchase_info_tab ,主模板我需要模型Purchase和purchase_info_tab我需要Model購買,並且我們有兩個相同的查詢。我以某種方式避免這種情況?
@render_to('app/purchase_view.html')
def purchase_view(request, purchase_id):
try:
purchase = Purchase.objects.get(id=purchase_id)
except Purchase.DoesNotExist:
raise Http404()
return {
'purchase': purchase,
}
@render_to('app/tabs/info_tab.html')
def purchase_info_tab(request):
purchase = #I load one model twice in one page
try:
itemsgroups = ItemsGroup.objects.filter(purchase=purchase).all()
except IndexError:
raise Http404()
return {
'itemsgroups': itemsgroups,
}
將緩存'Purchase'對象的工作? – dm03514 2012-02-26 15:24:09
怎麼樣?一個請求一次購買 – mikhail 2012-02-26 15:32:24