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

  • Home
  • SEARCH
  • 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 4614322
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:40:59+00:00 2026-05-22T01:40:59+00:00

i have created little search method. The problem that its hard to read it

  • 0

i have created little search method. The problem that its hard to read it and ordering seems to be “out of shape”. What is the best way to filter query in such manner?

@login_check
def search(request):
    subdomain = request.get_host()                                                                   
    q = request.GET.get('q', None)
    queryset = (
                    SomeObject.objects.filter(title__icontains=q)
                        .filter(alias=Site.objects.get(domain=subdomain)) \
                        .order_by('created') |
                    SomeObject.objects.filter(description__icontains=q)
                        .filter(alias=Site.objects.get(domain=subdomain)) \
                        .order_by('created') |
                    SomeObject.objects.filter(comment__icontains=q)
                        .filter(alias=Site.objects.get(domain=subdomain)) \
                        .order_by('created') |
                    SomeObject.objects.filter(email__icontains=q)
                        .filter(alias=Site.objects.get(domain=subdomain)) \
                        .order_by('created')
                )
    return object_list(queryset)

In this method object list forms what have to be given back so all i need to do is form a nice query.

Main problem i see here is that filters could be applied after contains
since its all the same. How can i achieve this? What is the best/nicest way to filter in such situation?

I’ve tired to set filters after creating query but then it trows that i cannot apply filters to queries only to model lists. I may be wrong since i’m writing this error from memory, but one thing for sure that it trowed an error.

P.S. I’m using Django 1.1 here and python 2.5.

  • 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-22T01:40:59+00:00Added an answer on May 22, 2026 at 1:40 am

    “Complex lookups with Q objects”

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

Sidebar

Related Questions

I have a little problem. I have some dynamically created tables and each row
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
I have created a few small flash widgets that stream .mp3 audio from an
i have created a workflow activity that do give the item creater of a
I've a little problem, I'd search google and my Wpf's books but I don't
I have created an NSMetadataQuery to search for all audio available through Spotlight, modelled
i have created a little slide show in jQuery. On clicking-n-dragging your mouse it
I have created a little drawing area class and now need a pixmap to
I have created this little program to calculate pi using probability and ratios. In

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.