Issue #5 wontfix
created an issue

What would be required to create a text search filter? In for example (that demo URL is not going to be around indefinitely), it would be useful to search on title and summary fields.

In this case, the user would not be presented with a list of choices, but a text box, and and the add/remove options.

Comments (8)

  1. Luke Plant repo owner

    Is it possible to add this logic inside the view function? FilterSet.qs returns a queryset that can be manipulated in the normal way, so you can layer the filtering done by the FilterSet with any other search functionality. So you could have a normal search input box, with a 'Search' button and a 'Clear' button. I think it should be possible to do this using normal HTML links/forms, without javascript.

    <form action="" method="GET">
      <input type=text name="search" value="{{ searchterms }}">
      <input type=submit name="searchbtn" value="Search">
      <input type=submit name="clearbtn" value="Clear">

    Then in the view

    books = Book.objects.all()
    if 'clearbtn' in request.GET:
        searchterms = None
        searchterms = request.GET.get('search', None)
    if searchterms:
       books = do_search(books)
    booksfilter = BookFilterSet(books, request.GET)
    return render(request, "booklist.html", 
      {'books': booksfilter.qs,
       'booksfilter': booksfilter,
       'searchterms': searchterms,

    If that works (and I haven't thought it through fully), that seems like a cleaner solution.

  2. evildmp reporter

    Yes in fact it does, I have a very crude version working.

    At this point, I think that the template that's a property of FilterSet perhaps needs to be moved from

    In fact the template for each filter should be associated with the appropriate Filter subclass, allowing different filter types to have different templates when required.

    In the case of the different template for a text search filter, the Filter subclass should be the same (i.e. it depends on the kind of field), but it should be possible to instantiate each one with an optional way of presenting it to the user.

    I'll take a look at that this evening.

  3. evildmp reporter

    Do you have a few minutes to chat about this on IRC? I think I have got as far as I can with the approach I started with. Probably it will be better now to start again from scratch, but it would be a great help to talk it over for a minute.

  4. Luke Plant repo owner

    I have an example which implements this without needing to use/patch easyfilters at all.



    Since the UI and mechanism for text search is quite different from clickable filters, I think this is much better implemented in this way. The only tricky thing is generating the hidden inputs so that query parameters are propagated, but it is a few lines of template code.

    Sorry I wasn't able to give this input before.

  5. evildmp reporter

    The version at allows this sort of thing:

        fields = [
            ('title', {
                "template": "django_easyfilters/text_search.html",
                "search_keys": [
                "filter_type": "search",
                "field_name": "Title/summary",

    where a search field can apply to more than one model field (e.g.. search for "Jane" in authors or titles), and permits different search types to be set up through the same interface.

    I can see that there's some advantage in keeping the search types separate, though.

  6. evildmp reporter

    How do you feel about moving the template to a file, just to make it easier to override by providing one in the project (or elsewhere)?

  7. Log in to comment