title: Implementing Django ForeignKey-like subqueries without ForeignKey
body: <p>I have a non-ForeignKey ID from an external system that acts as my join key. I'd like to do Django ORM style queries using this ID. </p>
  
  <p>My desired query is:</p>
  
  <pre><code>results = MyModel.objects.filter(level='M', children__name__contains='SOMETHING')
  </code></pre>
  
  <p>My model looks like this:</p>
  
  <pre><code>class MyModel(BaseModel):
      LEVELS = (
          ('I', 'Instance'),
          ('M', 'Master'),
          ('J', 'Joined')
      )
  
      level        = models.CharField(max_length=2, choices=LEVELS, default='I')
      parent       = models.ForeignKey('self', blank=True, null=True, related_name='children', on_delete=models.SET_NULL )
      master_id    = models.CharField(max_length=200)
      name         = models.CharField(max_length=300, blank=True, null=True)
  </code></pre>
  
  <p>This works fine with <code>parent</code> as a field, but parent is redundant with the <code>master_id</code> field: <code>master_id</code> indicates which children belong to which master node. I'd like to get rid of <code>parent</code> (primarily because the dataset is fairly large and setting the parent IDs when importing data takes a long time).</p>
  
  <p>The SQL equivalent of what I'm looking for is:</p>
  
  <pre><code>SELECT
      DISTINCT( s_m.master_id )
  FROM
      mytable s_m JOIN
      mytable s_i ON
          s_i.level = 'I' and s_m.level='M' AND s_i.master_id == s_m.master_id
  WHERE
      s_i.name like '%SOMETHING%';
  </code></pre>
  
  <p>I believe there's a way to use Manager or QuerySet to enable clean querying of children (in this case, the children's names) within the Django ORM framework, but I can't figure out how. Any pointers would be appreciated.</p>