Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Change ProductManager to ProductQuerySet

Anna Siwik4d2fbbf07b4f
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 8d658355f5..409c94323e 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -332,7 +332,7 @@ class AddVariantToDeliveryGroupForm(forms.Form):
""" Adds variant in given quantity to shipment group. """
variant = AjaxSelect2ChoiceField(
queryset=ProductVariant.objects.filter(
- product__in=Product.objects.get_available_products()),
+ product__in=Product.objects.available_products()),
fetch_data_url=reverse_lazy('dashboard:ajax-available-variants'))
quantity = QuantityField(
label=pgettext_lazy(
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 3591ffa896..d5ceafedf7 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -716,7 +716,7 @@ def ajax_available_variants_list(request):
variant.sku, variant.display_product(),
gross(variant.get_price_per_item(discounts)))
- available_products = Product.objects.get_available_products()
+ available_products = Product.objects.available_products()
queryset = ProductVariant.objects.filter(
product__in=available_products).prefetch_related('product')
search_query = request.GET.get('q', '')
@@ -741,7 +741,7 @@ def ajax_products_list(request):
"""
queryset = (
Product.objects.all() if request.user.has_perm('product.view_product')
- else Product.objects.get_available_products())
+ else Product.objects.available_products())
search_query = request.GET.get('q', '')
if search_query:
queryset = queryset.filter(Q(name__icontains=search_query))
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 4f4c0e0631..777a0cf164 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -83,12 +83,12 @@ class ProductClass(models.Model):
class_.__module__, class_.__name__, self.pk, self.name)
-class ProductManager(models.Manager):
- def get_available_products(self):
+class ProductQuerySet(models.QuerySet):
+ def available_products(self):
today = datetime.date.today()
- return self.get_queryset().filter(
- Q(available_on__lte=today) | Q(available_on__isnull=True)).filter(
- is_published=True)
+ return self.filter(
+ Q(available_on__lte=today) | Q(available_on__isnull=True),
+ Q(is_published=True))
class Product(models.Model, ItemRange):
@@ -105,7 +105,7 @@ class Product(models.Model, ItemRange):
updated_at = models.DateTimeField(auto_now=True, null=True)
is_featured = models.BooleanField(default=False)
- objects = ProductManager()
+ objects = ProductQuerySet.as_manager()
class Meta:
app_label = 'product'
diff --git a/saleor/product/utils.py b/saleor/product/utils.py
index e6453fdfe5..bd15a82571 100644
--- a/saleor/product/utils.py
+++ b/saleor/product/utils.py
@@ -19,7 +19,7 @@ def products_visible_to_user(user):
if user.is_authenticated and user.is_active and user.is_staff:
return Product.objects.all()
else:
- return Product.objects.get_available_products()
+ return Product.objects.available_products()
def products_with_details(user):