Improve search of packages, distributors and manufacturers
This commit is contained in:
parent
b65b5c12ce
commit
3abdd9b180
@ -161,9 +161,18 @@ class PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
if not search:
|
if not search:
|
||||||
return qs
|
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
|
return qs
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
@ -214,9 +223,10 @@ class DistributorView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
if not search:
|
if not search:
|
||||||
return qs
|
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
|
return qs
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
@ -741,9 +751,11 @@ class ManufacturersViewSet(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
if not search:
|
if not search:
|
||||||
return qs
|
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
|
return qs
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user