本文整理汇总了Python中products.models.Product.filters_data方法的典型用法代码示例。如果您正苦于以下问题:Python Product.filters_data方法的具体用法?Python Product.filters_data怎么用?Python Product.filters_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类products.models.Product
的用法示例。
在下文中一共展示了Product.filters_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ajax_products_analysis
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import filters_data [as 别名]
def ajax_products_analysis(request):
data = dict()
switcher = request.GET.get('analysis')
queryset = Product.my_query.active_warehouse()
queryset = Product.filters_data(request, queryset)
queryset_analysis = [0, 0, 0] # total_qty, #total_warehouse_value, #total_sell_value
if switcher == 'warehouse_analysis':
queryset_analysis[0] = queryset.aggregate(Sum('qty'))['qty__sum'] if queryset else 0
queryset_analysis[1] = queryset.aggregate(total=Sum(F('qty') * F('price_buy')))['total'] if queryset else 0
queryset_analysis[2] = queryset.aggregate(total=Sum(F('qty') * F('final_price')))['total'] if queryset else 0
data['results'] = render_to_string(request=request,
template_name='report/ajax/warehouse/ajax_warehouse_analysis.html',
context={'queryset_analysis': queryset_analysis,
'currency': CURRENCY,
'switcher': switcher
}
)
if switcher == 'vendor_analysis':
vendor_analysis = queryset.values('supply__title').annotate(total_ware_price=Sum(F('qty')*F('final_price')),
total_sell_price=Sum(F('qty')*F('price_buy'))
).order_by('supply__title')
data['results'] = render_to_string(request=request,
template_name='report/ajax/warehouse/ajax_warehouse_analysis.html',
context={'vendor_analysis': vendor_analysis,
'currency': CURRENCY,
'switcher': switcher,
}
)
if switcher == "sells_analysis":
sells_items = RetailOrderItem.objects.filter(title__in=queryset) if queryset else None
sells_analysis = sells_items.values('title__title').annotate(total_sells=Sum(F('qty')),
incomes=Sum(F('qty')*F('final_price'))
).order_by('-incomes')[:30]
data['results'] = render_to_string(request=request,
template_name='report/ajax/warehouse/ajax_warehouse_analysis.html',
context={ 'sells_analysis': sells_analysis,
'currency': CURRENCY,
'switcher': switcher
}
)
if switcher == 'buy_analysis':
pass
return JsonResponse(data)