本文整理匯總了Python中models.Category.get_tree方法的典型用法代碼示例。如果您正苦於以下問題:Python Category.get_tree方法的具體用法?Python Category.get_tree怎麽用?Python Category.get_tree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Category
的用法示例。
在下文中一共展示了Category.get_tree方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: common_pieces
# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import get_tree [as 別名]
def common_pieces(request):
categories = Category.get_tree()
if request.is_ajax():
template = 'base_ajax.html'
else:
template = 'base.html'
return {
'base_template': template,
'shop': {
'basket': Basket(request),
'categories': categories
}
}
示例2: category
# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import get_tree [as 別名]
def category(request, path=None):
tree = Category.get_tree()
res = {}
if path is None:
res['root'] = tree[0]
else:
if path.endswith('.html'):
ware_slug = path.split('/')[-1][:-5]
path = path[0:len(path)-len(ware_slug)-6]
res['ware'] = Ware.objects.get(slug=ware_slug)
res['TEMPLATE'] = 'shop/ware.html'
candidates = [x for x in tree if x._materialized_path == path]
if len(candidates) <> 1:
raise Http404
res['root'] = candidates[0]
return res