title: Representing a Django model that holds permutations of ForeignKeys
body: <p>I'm working on a project in Django for blind testing, and I would like to know about best practices for database structure. </p>
  
  <p>Here is a simplified version of my code to demonstrate the issue I'm having:</p>
  
  <pre><code>class Product(models.Model):
      name = models.CharField(max_length=200)
  
  class Test(models.Model):
      product_a = models.ForeignKey(Product, related_name='a_products')
      product_b = models.ForeignKey(Product, related_name='b_products')
  
  class Trial(models.Model):
      test = models.ForeignKey(Test)
  
      # Is there a more elegant way to represent the fact that these three
      # variables are all a permutation of test.product_a and test.product_b?
      order_1 = models.ForeignKey(Product, related_name='orders_1')
      order_2 = models.ForeignKey(Product, related_name='orders_2')
      order_3 = models.ForeignKey(Product, related_name='orders_3')
  </code></pre>
  
  <p>My models are roughly set up like this. There are many <code>Trials</code> for a single <code>Test</code>. A <code>Trial</code> needs to hold a three-element permutation of its <code>test.product_a</code> and <code>test.product_b</code>. The way I have it set up now doesn't capture that at all, and it just seems really inelegant. I've considered mapping integers to permutations, and storing the integer corresponding to the permutation, but that doesn't seem great either. I don't know much about databases at all, so I would love to hear a better way to structure this. Thanks!</p>