私は次のDjangoモデルを持っています: -
class Company(models.Model):
name = models.CharField(max_length=50)
is_active = models.BooleanField(db_index=True)
class Phase(models.Model):
company = models.ForeignKey(Company)
name = models.CharField(max_length=50)
is_active = models.BooleanField(db_index=True)
class Process(models.Model):
company = models.ForeignKey(Company)
name = models.CharField(max_length=50)
phases = models.ManyToManyField(Phase, through='ProcessPhase')
is_active = models.BooleanField(db_index=True)
class ProcessPhase(models.Model):
process = models.ForeignKey(Process)
phase = models.ForeignKey(Phase)
order = models.PositiveIntegerField(help_text="At what step of your process will this phase occur?", unique=True)
「企業」には「プロセス」と「フェーズ」があります。(会社の) プロセスは、(会社の) 1 つ以上のフェーズで構成されます。プロセスに関連付けられた各フェーズには「順序」があります。要件は次のとおりです。 -
- 企業の特定のプロセスでは、フェーズは 1 回だけ出現します。
- また、プロセス内の「フェーズ A」と「フェーズ B」は同じ順序にすることはできません。
だから私は知る必要があります: -
a) 上記の要件を満たすために、モデル定義でいくつかの「固有」を指定する方法。
b) ManyToManyField によって自動的に暗示される一意性は、ある場合、どのようなものですか?