title: What lookup can I use for this issue?
body: <p>I have the following Django model:</p>
  
  <pre><code>class MyModel(models.Model):
      [...]
      parent = models.ForeignKey('self', related_name="children", null=True, blank=True)
      [...]
  </code></pre>
  
  <p>What I'm trying to do is count how many parents and grandparents a certain instance of the model has. That is, if <code>instance_1</code> is the parent of <code>instance_2</code>, and <code>instance_2</code> is the parent of <code>instance_3</code>, then <code>instance_3</code> has a value of 2 (its parent, and the parent of its parent).</p>
  
  <p>The trick is I'm trying to do this in a queryset as to do some filtering based on that value.</p>
  
  <pre><code>MyModel.objects.filter(??)
  </code></pre>
  
  <p>How can I go about doing that?
  I thought about using <code>annotate</code> and <code>Count</code> and then filtering based on that, but again I'm not sure how to go about it.</p>