Skip to content

Commit

Permalink
67 admin autocomplete fields are not working (#71)
Browse files Browse the repository at this point in the history
* define get_search_results to fix autocomplete search errors

* use django's cl.get_request as is to avoid poor performance
  • Loading branch information
EricOuma authored Jan 22, 2024
1 parent 1ae416d commit d458743
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions django_typesense/changelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,20 @@ def get_typesense_results(self, request):

def get_queryset(self, request):
# this is needed for admin actions that call cl.get_queryset
# To reduce the trips use max per_page
self.list_per_page = 250
ids = []
while True:
results = self.get_typesense_results(request)
if not results["hits"]:
break

ids.extend([result["document"]["id"] for result in results["hits"]])
self.page_num += 1

return self.model.objects.filter(id__in=ids)
# TODO: The uncommented code below introduces a issue. Search filters passed to typesense not available here.
# Maybe look for a way to reverse enmgineer or a better solution to the uncommented cose that is lazy
# like django querysets.
# To reduce the trips use max per_page
# self.list_per_page = 250 # Updated but not used, check self.model_admin.list_per_page
# ids = []
# while True:
# results = self.get_typesense_results(request)
# if not results["hits"]:
# break
#
# ids.extend([result["document"]["id"] for result in results["hits"]])
# self.page_num += 1
#
# return self.model.objects.filter(id__in=ids)
return super().get_queryset(request)

0 comments on commit d458743

Please sign in to comment.