title: Django find object with 2 matching fields in for loop
body: <p>I have an array of Product Object id’s: <code>['ypxiQsnL4Etm', 'eWGzBlgcBy5l', 'ki5H4U4unB2v']</code></p>
  <p>And I have a 'Deal' object that has 2 fields with product 1 and 2.</p>
  <pre><code>class Deal(models.Model):
      name = models.CharField(max_length=50, null=True)
      product1 = models.ForeignKey(Product, on_delete=models.CASCADE, blank=True, null=True,
                                   related_name='product1_product')
      product2 = models.ForeignKey(Product, on_delete=models.CASCADE, blank=True, null=True,
                                   related_name='product2_product')
  </code></pre>
  <p>I want to loop through that array and see which of those arrays are in the same Deal object. If one of those id’s are in the same object, that is a match. After the match is found, delete the id`s that matched from the array.</p>
  <p>I tried the following: <br/></p>
  <pre><code>for i in cart:
      try:
          product = Product.objects.get(product_id=i)
          if product.deal_type:
              product_id = product.product_id
              combi_products.append(product_id)
              print(combi_products)
  
      except:
          pass
  
  length = len(combi_products)
  if length &gt; 1:
       # Possible solution from markwalker - third try
       # match = Deal.objects.filter(Q(product1__product_id__in=combi_products) | Q(product2__product_id__in=combi_products))
          # if match:
          #     print('test', match)
      for cp in combi_products:
          try:
              deal_1 = Deal.objects.get(product1__product_id=cp)
              if deal_1:
                  try:
                      print(cp)
                      # My try
                      #matched_through = Deal.objects.get(product1__product_id=deal_1.product1.product_id, product2__product_id=cp)
                      #print(matched_through)
  
                      # Possible solution from AjayLingayat - second try
                       #matched_through = Deal.objects.get(product1__product_id=cp, product2__product_id=cp)
                       #print(matched_through)
                  except:
                      pass
          except:
              pass
  </code></pre>
  <p>Example of a matched Deal object with the product object ID`s from the array:</p>
  <pre><code># The array
  combi_products = ['ypxiQsnL4Etm', 'eWGzBlgcBy5l', 'ki5H4U4unB2v']
  
  # Match
  Deal.object.get(product1__product_id='ypxiQsnL4Etm', product2__product_id='ki5H4U4unB2v')
  
  # array after match
  combi_products.remove('ypxiQsnL4Etm')
  combi_products.remove('ki5H4U4unB2v')
  combi_products = ['eWGzBlgcBy5l']
  </code></pre>