mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-25 09:22:21 +00:00
SQL efficiency on asset list
This commit is contained in:
@@ -38,12 +38,12 @@ class AssetList(LoginRequiredMixin, generic.ListView):
|
|||||||
# TODO Feedback to user when search fails
|
# TODO Feedback to user when search fails
|
||||||
query_string = form.cleaned_data['q'] or ""
|
query_string = form.cleaned_data['q'] or ""
|
||||||
if len(query_string) == 0:
|
if len(query_string) == 0:
|
||||||
queryset = self.model.objects.all()
|
queryset = self.model.objects.all().select_related('category', 'status')
|
||||||
elif len(query_string) >= 3:
|
elif len(query_string) >= 3:
|
||||||
queryset = self.model.objects.filter(
|
queryset = self.model.objects.filter(
|
||||||
Q(asset_id__exact=query_string) | Q(description__icontains=query_string) | Q(serial_number__exact=query_string))
|
Q(asset_id__exact=query_string) | Q(description__icontains=query_string) | Q(serial_number__exact=query_string)).select_related('category', 'status')
|
||||||
else:
|
else:
|
||||||
queryset = self.model.objects.filter(Q(asset_id__exact=query_string))
|
queryset = self.model.objects.filter(Q(asset_id__exact=query_string)).select_related('category', 'status')
|
||||||
|
|
||||||
if form.cleaned_data['category']:
|
if form.cleaned_data['category']:
|
||||||
queryset = queryset.filter(category__in=form.cleaned_data['category'])
|
queryset = queryset.filter(category__in=form.cleaned_data['category'])
|
||||||
|
|||||||
Reference in New Issue
Block a user