title: Django filtering with nested queries
body: <p>I have a Django model that looks roughly like this</p>
  
  <pre><code>class Equipment(models.Model):
      id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
      name = models.CharField(max_length=100)
  
  class Tag(models.Model):  
      id = models.UUIDField(default=uuid.uuid4, unique=True, primary_key=True)
      tag_type = models.ForeignKey(TagType)
      equipment = models.ForeignKey(Equipment)
      name = models.CharField(max_length=100)
  
      class Meta:
          db_table = "tag"
          ordering = ["tag_type__name", "name"]
          unique_together = (("tag_type", "equipment"),)
  
  class TagType(models.Model):  
      id = models.PositiveSmallIntegerField(primary_key=True)
      name = models.CharField(max_length=100, unique=True)
  
      class Meta:
          db_table = "tag_type"
          ordering = ["name"]
  </code></pre>
  
  <p>TagTypes have names such as "Equipment" and "Load"</p>
  
  <p>"Equipment" tags can be "HVAC" or "Lighting"</p>
  
  <p>"Load" tags can be "Variable" or "Weather"</p>
  
  <p>I want to be able to filter to equipment that have a certain tag_type with a tag name. </p>
  
  <p>If I want equipment that have an <code>HVAC</code> tag with tag_type <code>Equipment</code> the following works:
  <code>Equipment.objects.filter(tag__tag_type__name="Equipment", tag__name="HVAC")</code></p>
  
  <p>However, I believe that in this case the tag_type name and the tag aren't necessarily from the same tag. AKA <code>tag__tag_type__name="Equipment"</code> and <code>tag__name="HVAC"</code> might not be referring with the right values.</p>
  
  <p>Since there can be many different types of tags with diverse names, I want to make sure I'm filtering to the right one. Is there a way I can manage this?</p>