Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9179035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:41:46+00:00 2026-06-17T17:41:46+00:00

I have troubles using the search_fields when the search expression has multiple words and

  • 0

I have troubles using the search_fields when the search expression has multiple words and i want to perform a startswith search

I have a class

class Foo(models.Model):
  kw = models.CharField(max_length = 255)
  ...

class FooAdmin(admin.ModelAdmin):
  search_fields = ('^kw',)

The '^' indicates that i want to perform a startswith search. If i’m looking for the kw ‘foo fuu’, django will perform the query:

select * from app_foo where `foo`.`kw` like 'foo%' and `foo`.`kw` like 'fuu%' 

This query obviously gives zero results. What should i do to make the engine looking for 'foo fuu%' ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:41:48+00:00Added an answer on June 17, 2026 at 5:41 pm

    How about override self.query so split() doesn’t work?

    from django.contrib.admin.views.main import ChangeList
    
    
    class UnsplitableUnicode(str):
        "An object that behaves like a unicode string but cannot be split()"
        def split(self, *args, **kwargs):
            return [self]
    
    class MultiWordSearchChangeList(ChangeList):
        "Changelist that allows searches to contain spaces"
        def get_query_set(self, request):
            self.query = UnsplitableUnicode(self.query)
            return super(MultiWordSearchChangeList, self).get_query_set(request)
    
    class FooAdmin(admin.ModelAdmin):
        def get_changelist(self, request, **kwargs):
            return MultiWordSearchChangeList
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have troubles using a foreign protocol in Objective-C. Is there any other solution
I have big troubles dealing with a website I want to make a searchfunction
I currently have a MySQL database that I am accessing using PHP. You search
I have trouble using sed. I need to replace some lines in very deprecated
I have trouble parsing a HTML table using Nokogiri and Ruby. My HTML table
I am have trouble converting my xml using XSLT back to xml in the
Having a bit of trouble using the List.Find with a custom predicate i have
I'm having some trouble using constraints correctly. I have three tables, 'item', 'store' and
I have a ASP.NET MVC site using Membership Provider. I have trouble testing some
i am developing an android app using phonegap. I have trouble displaying special characters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.