これらのモデルを前提として、FinancialTransactionが複数のThingに割り当てられるのを防ぐにはどうすればよいですか?
つまり、ThingOneにFinancialTransactionがある場合、ThingTwoまたはThingThreeはそれと関係を持つことができません。
管理者でこれを強制するにはどうすればよいですか?もちろん、Inlinesを使用してSomeThing管理者でThing *を取得することはできますが、これにより、複数のThing*を設定できます。
私の最初の傾向は、私のモデリングが間違っていて、すべてのモノを1つのモデルで表現する必要があるということですが、それらは間違いなく異なるタイプのモノです。
from django.db import models
class ThingOne(models.Model):
name = models.CharField(max_length=20)
some_things = models.ForeignKey('FinancialTransaction', blank = True, null = True)
class ThingTwo(models.Model):
name = models.CharField(max_length=20)
some_things = models.ForeignKey('FinancialTransaction', blank = True, null = True)
thingone = models.ForeignKey(ThingOne)
class ThingThree(models.Model):
name = models.CharField(max_length=20)
some_things = models.ForeignKey('FinancialTransaction', blank = True, null = True)
thingtwo = models.ForeignKey(ThingTwo)
class FinancialTransaction(models.Model):
value = models.IntegerField()