本文整理匯總了Python中products.models.Product.get_published_products方法的典型用法代碼示例。如果您正苦於以下問題:Python Product.get_published_products方法的具體用法?Python Product.get_published_products怎麽用?Python Product.get_published_products使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類products.models.Product
的用法示例。
在下文中一共展示了Product.get_published_products方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rubricator
# 需要導入模塊: from products.models import Product [as 別名]
# 或者: from products.models.Product import get_published_products [as 別名]
def rubricator(request):
rubric_id = request.GET.get("rubric", None)
rubric = None
rubrics = Rubric.get_published_rubrics().filter(parent=None)
if rubric_id is not None :
try:
rubric = Rubric.objects.get(id=rubric_id)
except Rubric.DoesNotExist :
return error(request, u"Нет рубрики с таким идентификатором!", u"")
rubricator_path = []
parents_id = []
rubrics_view = rubrics
products = Product.get_published_products()
products_count = products.count()
if rubric is not None :
rubricator_path = rubric.rubricator_path()
parents_id = map(lambda r: r.id, rubricator_path)
all_children = rubric.get_all_published_children()
products = products.filter(Q(rubrics__in=all_children)|Q(rubrics__in=[rubric]))
rubrics_view = all_children
if len(rubrics_view) :
products = products.order_by("?")[:21]
else:
products_count = products.count()
paginator = Paginator(products, 21)
page = request.GET.get('page')
try:
products = paginator.page(page)
except PageNotAnInteger:
products = paginator.page(1)
except EmptyPage:
products = paginator.page(paginator.num_pages)
else:
products = products.order_by("?")[:21]
return render_to_response("rubrics/rubrics.html", {'main': rubric, 'products':products, 'products_count':products_count, 'rubrics_view':rubrics_view, 'rubrics':rubrics, 'parents_id':parents_id, 'rubricator_path':rubricator_path}, get_context(request))