Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Index products, orders and users
Artur Smęt0e61ae0ddf4c
diff --git a/saleor/order/models.py b/saleor/order/models.pyindex 9ea0858cd4..9cd0470d4e 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -22,6 +22,7 @@ from ..core.utils import build_absolute_urifrom ..discount.models import Voucherfrom ..product.models import Product, Stockfrom ..userprofile.models import Address+from ..search import indexfrom . import Status@@ -45,7 +46,7 @@ class OrderManager(models.Manager):@python_2_unicode_compatible-class Order(models.Model, ItemSet):+class Order(models.Model, ItemSet, index.Indexed):status = models.CharField(pgettext_lazy('Order field', 'order status'),max_length=32, choices=Status.CHOICES, default=Status.NEW)@@ -85,6 +86,12 @@ class Order(models.Model, ItemSet):objects = OrderManager()+ search_fields = [+ index.SearchField('id'),+ index.SearchField('get_user_current_email'),+ index.SearchField('_index_billing_phone'),+ index.SearchField('_index_shipping_phone')]+class Meta:ordering = ('-last_status_change',)@@ -114,6 +121,13 @@ class Order(models.Model, ItemSet):else:return self.user_email+ def _index_billing_phone(self):+ billing_address = self.billing_address+ return billing_address.phone++ def _index_shipping_phone(self):+ return self.shipping_address.phone+def __iter__(self):return iter(self.groups.all())diff --git a/saleor/product/models/base.py b/saleor/product/models/base.pyindex 54bde0915d..d125d89d05 100644--- a/saleor/product/models/base.py+++ b/saleor/product/models/base.py@@ -22,6 +22,7 @@ from versatileimagefield.fields import VersatileImageFieldfrom ...discount.models import get_variant_discountsfrom .fields import WeightFieldfrom .utils import get_attributes_display_map+from ...search import index@python_2_unicode_compatible@@ -93,7 +94,7 @@ class ProductManager(models.Manager):@python_2_unicode_compatible-class Product(models.Model, ItemRange):+class Product(models.Model, ItemRange, index.Indexed):product_class = models.ForeignKey(ProductClass, related_name='products')name = models.CharField(pgettext_lazy('Product field', 'name'), max_length=128)@@ -117,6 +118,11 @@ class Product(models.Model, ItemRange):objects = ProductManager()+ search_fields = [+ index.SearchField('name', partial_match=True),+ index.SearchField('description'),+ index.FilterField('available_on')]+class Meta:app_label = 'product'diff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.pyindex e6a1cb8c82..e9acbcd6c7 100644--- a/saleor/userprofile/models.py+++ b/saleor/userprofile/models.py@@ -8,6 +8,7 @@ from django.utils import timezonefrom django.utils.encoding import python_2_unicode_compatiblefrom django.utils.translation import pgettext_lazyfrom django_countries.fields import Country, CountryField+from ..search import indexclass AddressManager(models.Manager):@@ -116,7 +117,7 @@ class UserManager(BaseUserManager):return entry-class User(PermissionsMixin, AbstractBaseUser):+class User(PermissionsMixin, AbstractBaseUser, index.Indexed):email = models.EmailField(unique=True)addresses = models.ManyToManyField(Address, blank=True)is_staff = models.BooleanField(@@ -141,6 +142,9 @@ class User(PermissionsMixin, AbstractBaseUser):objects = UserManager()+ search_fields = [+ index.SearchField('email')]+def get_full_name(self):return self.email