Replaces a bunch of len(queryset) with queryset.count()
This commit is contained in:
parent
1c6dc12781
commit
5716af0afa
1 changed files with 9 additions and 9 deletions
|
@ -48,11 +48,11 @@ class CategoryConditionController(ConditionController):
|
||||||
enabling_products = rego.Product.objects.filter(
|
enabling_products = rego.Product.objects.filter(
|
||||||
category=self.condition.enabling_category,
|
category=self.condition.enabling_category,
|
||||||
)
|
)
|
||||||
products = rego.ProductItem.objects.filter(
|
products_count = rego.ProductItem.objects.filter(
|
||||||
cart=carts,
|
cart=carts,
|
||||||
product__in=enabling_products,
|
product__in=enabling_products,
|
||||||
)
|
).count()
|
||||||
return len(products) > 0
|
return products_count > 0
|
||||||
|
|
||||||
|
|
||||||
class ProductConditionController(ConditionController):
|
class ProductConditionController(ConditionController):
|
||||||
|
@ -67,11 +67,11 @@ class ProductConditionController(ConditionController):
|
||||||
condition in one of their carts '''
|
condition in one of their carts '''
|
||||||
|
|
||||||
carts = rego.Cart.objects.filter(user=user, released=False)
|
carts = rego.Cart.objects.filter(user=user, released=False)
|
||||||
products = rego.ProductItem.objects.filter(
|
products_count = rego.ProductItem.objects.filter(
|
||||||
cart=carts,
|
cart=carts,
|
||||||
product__in=self.condition.enabling_products.all(),
|
product__in=self.condition.enabling_products.all(),
|
||||||
)
|
).count()
|
||||||
return len(products) > 0
|
return products_count > 0
|
||||||
|
|
||||||
|
|
||||||
class TimeOrStockLimitConditionController(ConditionController):
|
class TimeOrStockLimitConditionController(ConditionController):
|
||||||
|
@ -155,8 +155,8 @@ class VoucherConditionController(ConditionController):
|
||||||
|
|
||||||
def is_met(self, user, quantity):
|
def is_met(self, user, quantity):
|
||||||
''' returns True if the user has the given voucher attached. '''
|
''' returns True if the user has the given voucher attached. '''
|
||||||
carts = rego.Cart.objects.filter(
|
carts_count = rego.Cart.objects.filter(
|
||||||
user=user,
|
user=user,
|
||||||
vouchers=self.condition.voucher,
|
vouchers=self.condition.voucher,
|
||||||
)
|
).count()
|
||||||
return len(carts) > 0
|
return carts_count > 0
|
||||||
|
|
Loading…
Reference in a new issue