Improve search of packages, distributors and manufacturers

This commit is contained in:
Mario Hüttel 2021-11-15 17:57:01 +01:00
parent b65b5c12ce
commit 3abdd9b180

View File

@ -161,9 +161,18 @@ class PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
if not search:
return qs
search = search.strip()
search_fragments = search.strip().split()
for search in search_fragments:
if search.lower() == 'smd':
s_filter = Q(name__icontains = search) | Q(smd = True)
else:
try:
pin_count = int(search)
s_filter = Q(name__icontains = search) | Q(pin_count=pin_count)
except:
s_filter = Q(name__icontains = search)
qs = qs.filter(Q(name__icontains = search))
qs = qs.filter(s_filter)
return qs
def get_context_data(self, **kwargs):
@ -214,9 +223,10 @@ class DistributorView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
if not search:
return qs
search = search.strip()
search_fragments = search.strip().split()
qs = qs.filter(Q(name__icontains = search) | Q(website__icontains = search))
for search in search_fragments:
qs = qs.filter(Q(name__icontains = search) | Q(website__icontains = search))
return qs
def get_context_data(self, **kwargs):
@ -741,9 +751,11 @@ class ManufacturersViewSet(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
if not search:
return qs
search = search.strip()
search_fragements = search.strip().split()
for search in search_fragements:
qs = qs.filter(Q(name__icontains = search) | Q(website__icontains = search))
qs = qs.filter(Q(name__icontains = search) | Q(website__icontains = search))
return qs
def get_context_data(self, **kwargs):