title: How do you condense this into one query
body: <p>I have the following Model:</p>
  
  <pre><code>class ReportLayout(models.Model):
      company = models.ForeignKey(Company, blank=True, null=True)
      name = models.CharField(max_length=64)
      ...
      class Meta:
          ordering = ('name', )
  </code></pre>
  
  <p>And the following ModelManager method:</p>
  
  <pre><code>def for_company(self, company):
      names = self.filter(company=company).values_list('name', flat=True)
      public_ids = self.filter(company__isnull=True).exclude(
          name__in=names).values_list('id', flat=True)
      return self.filter(Q(company=company)|Q(id__in=public_ids))
  </code></pre>
  
  <p>The idea is to get all of the ReportLayouts for a company.  Those consist of:</p>
  
  <ol>
  <li>ReportLayouts that belong to the company, </li>
  <li>All the public/shared ReportLayouts (where company=null) that don't have a matching name in 1 above.</li>
  </ol>
  
  <p>So, if I have 3 ReportLayouts:</p>
  
  <pre><code>id Name  Company
  1  A     null
  2  B     null
  3  B     Company1
  </code></pre>
  
  <p><code>for_company(Company1)</code> should return the ReportLayouts that have IDs 1 and 3</p>
  
  <p>Seems like I should be able to write it in one query, but the best I have so far is 3.  The problem stems from the .filter/.exclude pair of functions and the missing __notin operator.</p>
  
  <p>I want the ability to do <code>.count()</code> and I want the ordering that the query is providing is why I don't just do it in 2 queries.  But how I do it in one is completely eluding me.</p>