本文整理汇总了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))