Skip to content

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

Add first and last name in dashboard search

fowczarek59e533b88b15
diff --git a/saleor/dashboard/customer/filters.py b/saleor/dashboard/customer/filters.py
index 3167a48a51..9a3740a138 100644
--- a/saleor/dashboard/customer/filters.py
+++ b/saleor/dashboard/customer/filters.py
@@ -27,7 +27,7 @@ IS_ACTIVE_CHOICES = (
class UserFilter(SortedFilterSet):
name_or_email = CharFilter(
- label=pgettext_lazy('Customer name or email filter', 'Name or email'),
+ label=pgettext_lazy('Customer name or email filter', 'Name or email'),
method='filter_by_customer')
location = CharFilter(
label=pgettext_lazy('Customer list filter label', 'Location'),
diff --git a/saleor/search/backends/postgresql_dashboard.py b/saleor/search/backends/postgresql_dashboard.py
index f0e2728691..265d40fac8 100644
--- a/saleor/search/backends/postgresql_dashboard.py
+++ b/saleor/search/backends/postgresql_dashboard.py
@@ -40,6 +40,8 @@ def search_orders(phrase):
def search_users(phrase):
"""Return matching users for dashboard views."""
sv = (SearchVector('email', weight='A') +
+ SearchVector('first_name', weight='B') +
+ SearchVector('last_name', weight='B') +
SearchVector('default_billing_address__first_name', weight='B') +
SearchVector('default_billing_address__last_name', weight='B'))
rank = SearchRank(sv, SearchQuery(phrase))
diff --git a/saleor/search/documents.py b/saleor/search/documents.py
index 48c624af2d..163513c8c3 100644
--- a/saleor/search/documents.py
+++ b/saleor/search/documents.py
@@ -44,12 +44,16 @@ class UserDocument(DocType):
return instance.email
def prepare_first_name(self, instance):
+ if instance.first_name:
+ return instance.first_name
address = instance.default_billing_address
if address:
return address.first_name
return None
def prepare_last_name(self, instance):
+ if instance.last_name:
+ return instance.last_name
address = instance.default_billing_address
if address:
return address.last_name