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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:11:45+00:00 2026-05-26T20:11:45+00:00

I am working on an application in Python/Django. I am trying to make a

  • 0

I am working on an application in Python/Django. I am trying to make a filter by reducing a list of Q objects with Python’s operator.or_ function.
Unfortunately it results in a list that is combined with an AND rather than operator.or_.
The problem occurs in the following code:

print 'operator.or_', operator.or_
filter = reduce(operator.or_, q_objects[key])
print key, '->', filter

The statement

print 'operator.or_', operator.or_

results in

operator.or_ <built-in function or_>

so that seems succesful.
However,

filter = reduce(operator.or_, q_objects[key])
print key, '->', filter    

results in (with added formatting)

some_key -> (
        AND: 
        ('some_field__icontains', u'search string 1'), 
        ('other_field__icontains', u'search string 2')
    )

As you can see, the result has an AND rather than an OR.
Can anyone see what I am doing wrong?

Regarding q_objects[key], it is created as follows:

q_dict = {'some_field__icontains': u'search string 1', 'other_field__icontains': u'search string 2'}
q_objects[key] = [Q(**q_dict)]
  • 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-26T20:11:46+00:00Added an answer on May 26, 2026 at 8:11 pm
    q_objects[type] = [Q(**q_dict)]
    

    No. You need to handle each element separately.

    q_objects[type] = [Q(**{k: v}) for (k, v) in q_dict.iteritems()]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make an chat application using python and django. I almost
I am working on a web application using Python (Django) and would like to
I'm working on making a simple server application with python, and I'm trying to
I'm running CentOS 5, and am trying to get a django application working with
I'm currently working on a social web application using python/django. Recently I heard about
I am working on a Python/django web application and I need to extract text
I have a web application im currently working on in python. I'm using Django
Imagine you have a web application written in Django and Python 2.65, and MySQL
I am working with a HTML application with Python. I usually use the %
I'm trying to get a trivial Django project working with Passenger on Dreamhost, following

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.