私はDjangoでブラインドテストのプロジェクトを進めています。データベース構造のベストプラクティスについて知りたいと思います。ForeignKeysの順列を保持するDjangoモデルを表現する
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')
私のモデルはおおよそ次のように設定されています。ここでは
は私がいる問題を実証するための私のコードの簡易版です。単一のTest
には多くのTrials
があります。 Trial
は、test.product_a
とtest.product_b
の3要素置換を保持する必要があります。私が今設定している方法では、それはまったく捕捉されません。そして、それは本当にうらやましいようです。私は整数を順列にマッピングし、その順列に対応する整数を格納することを考えましたが、それはどちらかといえば素晴らしいとは言えません。私はデータベースについて全く知らないので、これをより良い方法で構築したいと思っています。ありがとう!