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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:19:14+00:00 2026-05-22T18:19:14+00:00

I have the following data structure: FruitObject with fields FruitType and FruitColor . On

  • 0

I have the following data structure: FruitObject with fields FruitType and FruitColor. On the other hand I have FruitOffer (which is input by user). It has same fields as FruitObject and is being input by user (some kind of demand-support pairing system; we input FruitObjects and user input FruitOffers; the task is to pair them and see what a user has to offer us – to select only those FruitObjects that are equal to FruitOffers for specific user).

So logically I’ve used __in selection to get needed data:

select = FruitObject.objects.filter(FruitType__in=FruitOffer.objects.filter(user=request.user).values("FruitType"))

Now comes the hard part for me – I need to add FruitColor to the select and get many-to-many select that fulfills both conditions (for each fruitObject get offerObject that is BOTH of TYPE and COLOR)

select = FruitObject.objects.filter(FruitType__in=FruitOffer.objects.filter(user=request.user).values("FruitType"), FruitColor__in=FruitOffer.objects.filter(user=request.user).values("FruitColor"))

But comma is operating more like OR in this case and returns me all values that are of specific Type or of specific Color.

How do add AND condition to __in select? If i’d like to add more conditions (like price or taste), will it be done in same way? Thanks in advance.

  • 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-22T18:19:15+00:00Added an answer on May 22, 2026 at 6:19 pm

    The hard way.

    FruitObject.objects.filter(reduce(operator.or_, (Q(FruitColor=color, FruitType=type) for (color, type) in FruitOffer.objects.filter(user=request.user).values_list('FruitColor', 'FruitType'))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a requirement to create a data structure that has the following
I have the following data structure: [DataServiceEntity] public class User { public string RowKey
I have the following data structure: One ModelA has a nested collection of ModelBs.
I have the following data structure: data = [[{'Posit': '0', 'R': '0', 'B': '0',
I have the following data structure (a list of lists) [ ['4', '21', '1',
I have something like the following data structure: Category StartDateTime EndDateTime =============================================== 1 12/1/2009
I have an odd linq subquery issue. Given the following data structure: Parents Children
I have the following casting problem when my data structure sSpecificData contains a field
Let's assume I have the following file structure: data.py foo = [] bar =
I have following structure with example data: id season_id title 1 1 Intro 2

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.