Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move products objects to its own queryset object
NyanKiyoshie577c63ea3ce
diff --git a/saleor/core/models.py b/saleor/core/models.pyindex 2494d61125..7cbbc247d3 100644--- a/saleor/core/models.py+++ b/saleor/core/models.py@@ -48,13 +48,6 @@ class PublishedQuerySet(models.QuerySet):return self.all()return self.published()- def collection_sorted(self, user):- qs = self.visible_to_user(user).prefetch_related(- "collections__products__collectionproduct"- )- qs = qs.order_by(F("collectionproduct__sort_order").desc(nulls_last=True))- return qs-class PublishableModel(models.Model):publication_date = models.DateField(blank=True, null=True)diff --git a/saleor/product/models.py b/saleor/product/models.pyindex 9b694d0c30..dcbc116180 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -5,6 +5,7 @@ from django.conf import settingsfrom django.contrib.postgres.fields import HStoreField, JSONFieldfrom django.core.validators import MinValueValidatorfrom django.db import models+from django.db.models import Ffrom django.urls import reversefrom django.utils.encoding import smart_textfrom django.utils.text import slugify@@ -23,7 +24,7 @@ from saleor.core.utils import build_absolute_urifrom ..core import TaxRateTypefrom ..core.exceptions import InsufficientStock-from ..core.models import PublishableModel, SortableModel+from ..core.models import PublishableModel, PublishedQuerySet, SortableModelfrom ..core.utils.taxes import apply_tax_to_pricefrom ..core.utils.translations import TranslationProxyfrom ..core.weight import WeightUnits, zero_weight@@ -108,6 +109,15 @@ class ProductType(models.Model):)+class ProductsQueryset(PublishedQuerySet):+ def collection_sorted(self, user):+ qs = self.visible_to_user(user).prefetch_related(+ "collections__products__collectionproduct"+ )+ qs = qs.order_by(F("collectionproduct__sort_order").desc(nulls_last=True))+ return qs++class Product(SeoModel, PublishableModel):product_type = models.ForeignKey(ProductType, related_name="products", on_delete=models.CASCADE@@ -131,6 +141,7 @@ class Product(SeoModel, PublishableModel):measurement=Weight, unit_choices=WeightUnits.CHOICES, blank=True, null=True)+ objects = ProductsQueryset.as_manager()translated = TranslationProxy()class Meta: