title: Django Filter by Multiple Foreign Key Properties
body: <p>So I have Django models which look like the following:</p>
  
  <pre><code>class Test(models.Model):
      cool_prop = models.CharField()
  
  class Metadata(models.Model):
       key = models.CharField()
       value = models.CharField()
       test = models.ForeignKey(Test)
  </code></pre>
  
  <p>and I would like to be able to filter tests based on if they contain a key:value pair based on this metadata. Essentially, I would like to be able to do:</p>
  
  <pre><code>tests = Test.objects.all().filter(metadata__key=key and metadata__value=value)
  </code></pre>
  
  <p>But I'm unsure how to perform this in Django. I've looked into F and Q statements. It seems as though most Django operations would allow any tests that has ANY metadata with said key and ANY metadata with said value. But I need the tests where 1 metadata matches in both key and value.</p>