MCPcopy Create free account
hub / github.com/django-haystack/django-haystack / SearchChangeList

Class SearchChangeList

haystack/admin.py:16–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14
15
16class SearchChangeList(ChangeList):
17 def __init__(self, **kwargs):
18 self.haystack_connection = kwargs.pop("haystack_connection", DEFAULT_ALIAS)
19 super_kwargs = kwargs
20 if django_version[0] >= 4:
21 super_kwargs["search_help_text"] = "Search..."
22 super().__init__(**super_kwargs)
23
24 def get_results(self, request):
25 if SEARCH_VAR not in request.GET:
26 return super().get_results(request)
27
28 # Note that pagination is 0-based, not 1-based.
29 sqs = (
30 SearchQuerySet(self.haystack_connection)
31 .models(self.model)
32 .auto_query(request.GET[SEARCH_VAR])
33 .load_all()
34 )
35
36 paginator = Paginator(sqs, self.list_per_page)
37 # Get the number of objects, with admin filters applied.
38 result_count = paginator.count
39 full_result_count = (
40 SearchQuerySet(self.haystack_connection).models(self.model).all().count()
41 )
42
43 can_show_all = result_count <= self.list_max_show_all
44 multi_page = result_count > self.list_per_page
45
46 # Get the list of objects to display on this page.
47 try:
48 result_list = paginator.page(self.page_num).object_list
49 # Grab just the Django models, since that's what everything else is
50 # expecting.
51 result_list = [result.object for result in result_list]
52 except InvalidPage:
53 result_list = ()
54
55 self.result_count = result_count
56 self.full_result_count = full_result_count
57 self.result_list = result_list
58 self.can_show_all = can_show_all
59 self.multi_page = multi_page
60 self.paginator = paginator
61
62
63class SearchModelAdminMixin:

Callers 1

changelist_viewMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…