title: Combining filter and exlude in Django query on related objects gives empty results
body: <p>I want to do the following query in Django to find car objects whose manufacturer doesn't exist in manufacturers table and have a specific country code:</p>
  
  <pre><code>ids = Countries.objects.all().values_list('id', flat=True)
  Cars.objects.filter(group__manufacturer__country=123).exclude(group__manufacturer__id__in=ids)
  </code></pre>
  
  <p>Unfortunately this gives me an empty query result. But executing the filter and exclude query alone gives non empty results where some of the objects are the same (i.e. fullfill both conditions). Therefore I'm wondering how to combine the queries to get the correct subset. I also tried using Djangos Q objects but unfortunately with the same results. If possible I would want to avoid using raw sql.</p>
  
  <p>Edit:</p>
  
  <p>SQL query looks like</p>
  
  <pre><code>SELECT * FROM "car"
     INNER JOIN "group" ON ("cars"."group_id" = "group"."id")
     INNER JOIN "manufacturertogroup" ON ("group"."id" = "manufacturertogroup"."group_id")
     WHERE (NOT ("cars"."group_id"
         IN (SELECT V2."group_id" FROM "manufacturertogroup" V2
         WHERE (V2."country" IN (SELECT U0."id" FROM "countries" U0)
         AND V2."group_id" IS NOT NULL))
         AND "cars"."group_id" IS NOT NULL)
         AND "manufacturertogroup"."country" = 123)
  </code></pre>