From 5716af0afa77139dec6148e62f66d594e45d8994 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Sat, 2 Apr 2016 15:56:27 +1100 Subject: [PATCH] Replaces a bunch of len(queryset) with queryset.count() --- registrasion/controllers/conditions.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/registrasion/controllers/conditions.py b/registrasion/controllers/conditions.py index a176522d..ebd43df9 100644 --- a/registrasion/controllers/conditions.py +++ b/registrasion/controllers/conditions.py @@ -48,11 +48,11 @@ class CategoryConditionController(ConditionController): enabling_products = rego.Product.objects.filter( category=self.condition.enabling_category, ) - products = rego.ProductItem.objects.filter( + products_count = rego.ProductItem.objects.filter( cart=carts, product__in=enabling_products, - ) - return len(products) > 0 + ).count() + return products_count > 0 class ProductConditionController(ConditionController): @@ -67,11 +67,11 @@ class ProductConditionController(ConditionController): condition in one of their carts ''' carts = rego.Cart.objects.filter(user=user, released=False) - products = rego.ProductItem.objects.filter( + products_count = rego.ProductItem.objects.filter( cart=carts, product__in=self.condition.enabling_products.all(), - ) - return len(products) > 0 + ).count() + return products_count > 0 class TimeOrStockLimitConditionController(ConditionController): @@ -155,8 +155,8 @@ class VoucherConditionController(ConditionController): def is_met(self, user, quantity): ''' returns True if the user has the given voucher attached. ''' - carts = rego.Cart.objects.filter( + carts_count = rego.Cart.objects.filter( user=user, vouchers=self.condition.voucher, - ) - return len(carts) > 0 + ).count() + return carts_count > 0