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 230215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:49:50+00:00 2026-05-11T19:49:50+00:00

I’m aware of full text search applications like Django Solr and solango, etc. What

  • 0

I’m aware of full text search applications like Django Solr and solango, etc.

What I’m looking to built is more akin to an advanced search for a real estate site.
E.g they can choose location, price, etc. similar to http://www.viewr.com advanced search.

What I have done so far is this, under the models custom manager:

def advanced_search(self, district, location, type, facilities, features, not_permitted):
        q_objects = []
        l_objects = []
        t_objects = []
        fc_objects = []
        ft_objects = []
        np_objects = []

        if district:
            if location:
                for loc in location:
                    l_objects.append(Q(location__exact=loc))
            else:
                l_objects.append(Q(location__district=district))


        if type:    
            for ty in type:
                t_objects.append(Q(listing_type__exact=ty))

        if facilities:    
            for fc in facilities:
                fc_objects.append(Q(property_facilities__exact=fc))

        if features:
            for ft in features:
                ft_objects.append(Q(property_features__exact=ft))
                ft_objects.append(Q(community_features__exact=ft))

        if not_permitted:    
            for np in not_permitted:
                np_objects.append(Q(not_permitted__exact=np))                              

        # Start with a bare QuerySet
        qs = self.get_query_set()

        if location:
            qs = qs.filter(reduce(operator.or_, l_objects))
        if type:
            qs = qs.filter(reduce(operator.or_, t_objects))
        if facilities:
            qs = qs.filter(reduce(operator.or_, fc_objects))
        if features:
            qs = qs.filter(reduce(operator.or_, ft_objects))
        if not_permitted:
            qs = qs.filter(reduce(operator.or_, np_objects))
        # Use operator's or_ to string together all of your Q objects.
        return qs

Right now I’m not getting very predictable results. Is there something I might be doing wrong? Is there a better way of doing the various OR searches/joins?

  • 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-05-11T19:49:50+00:00Added an answer on May 11, 2026 at 7:49 pm

    The closest I’ve come to this scenario is this post by Jacob:

    http://www.djangosnippets.org/snippets/32/

    What I’ve done is:

    def advanced_search(self, form):
            # It's easier to store a dict of the possible lookups we want, where
            # the values are the keyword arguments for the actual query.
            qdict = {'district': 'location__district',
              'location': 'location',
              'property_type': 'listing_type',
              'max_price': 'price__lte',
              'property_features': 'property_features',
              'community_features': 'community_features',
            }
    
            # Then we can do this all in one step instead of needing to call
            # 'filter' and deal with intermediate data structures.
            q_objs = [Q(**{qdict[k]: form.cleaned_data[k]}) for k in qdict.keys() if form.cleaned_data.get(k, None)]        
            search_results = RealEstateListing.objects.select_related().filter(*q_objs)
            return search_results
    

    It works fine when I pass single choices, but when passing multiple choices as for property facilities it chokes and says:

    OperationalError: Subquery returns more than 1 row

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

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.