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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:59:15+00:00 2026-05-28T05:59:15+00:00

I have a bunch of Widget objects. Now each widget has a string property

  • 0

I have a bunch of Widget objects.

Now each widget has a string property called ‘foo’. And I need to be able to query for Widgets that have ‘foo’ set to ‘red’, ‘orange’, ‘green’ or any arbitrary color, and include only Widgets that have that appropriate ‘foo’ property. Also, these colors are coming from user input, so I can’t trust them. I would rather not load all the results and then filter them, but rather do this in SQL.

However… I only see ways to join clauses with “AND”, never “OR”. And “in” is garbage (‘in’ only works on numerical IDs, or a sub-queryset, which reduces to the same problem!). I tried some other things, but they didn’t seem to work.

Basically, I’m asking how to express this as a key of filterQuery below.

myNiceWidgets = Widget.objects.filter(**filterQuery).orderBy(...)

Thanks.

  • 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-28T05:59:16+00:00Added an answer on May 28, 2026 at 5:59 am

    To use OR, look into django’s Q objects.

    https://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects

    Widget.objects.filter(Q(foo='red') | Q(foo='green'), **filterQuery)
    

    It won’t work as a key of filterQuery as the Q object must be a positional argument.

    Lookup functions can mix the use of Q objects and keyword arguments.
    All arguments provided to a lookup function (be they keyword arguments
    or Q objects) are “AND”ed together. However, if a Q object is
    provided, it must precede the definition of any keyword arguments. For
    example:

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

Sidebar

Related Questions

I have a page that has a bunch of widgets on it. Each widget
I have a bunch of files that I need to be able to transport
I have a QTreeWidget with a bunch of QTreeWidgetItems. Each item has a couple
I have source in a bunch of subdirectories like: src/widgets/apple.cpp src/widgets/knob.cpp src/tests/blend.cpp src/ui/flash.cpp In
I have an included javascript file thats initializes an empty array object called widgets
I have an application where i used Gallery widget to show a bunch of
I've got a page with a bunch of items on it. Each item has
I have a tabactivity with several tabs. Each tab has an ActivityGroup associated with
i have bunch of rows containing http://www.domainname.com i need to update those so http://
I have two widgets (Real and Fake) and one of them has a QPushButton.

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.