-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search without index #11
Comments
The only real reason is that I was replicating the functionality of the built-in choosers, where the search box always uses Wagtail search backends. Supporting SQL-based search as a fallback would be a worthwhile addition. |
Subclassing # views.py
from generic_chooser.views import ModelChooserViewSet, ModelChooserMixin
from taggit.models import Tag
class TagChooserMixin(ModelChooserMixin):
"""Custom Mixin to enable searching of non-indexed taggit.Tag model."""
@property
def is_searchable(self):
return True
def get_object_list(self, search_term=None, **kwargs):
object_list = self.get_unfiltered_object_list()
if search_term:
object_list = object_list.filter(name__icontains=search_term)
return object_list
class TagChooserViewSet(ModelChooserViewSet):
chooser_mixin_class = TagChooserMixin
icon = 'tag'
model = Tag
page_title = "Choose a Tag"
per_page = 10
order_by = 'name'
fields = ['name', ] |
@cspollar - thanks for that, works great I do get a 2nd search pagination message going on inside the main pagination though. Do you see this? |
Ahhh ... it's all in the placing of the "listing" element in the results template. Great solution, thanks again! |
Why do we need an index for simple search functionality? Wouldn't it be easier to suppport simple
contains
byfield(s)
?The text was updated successfully, but these errors were encountered: