I have the following Django models: -
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)
A "company" has its "processes" and "phases". A process (of a company) is comprised of one or more phases (of the company). Each phase associated with a process has an "order". The requirement is that: -
- in a particular process of a company, a phase can appear only once;
- also "phase A" and "phase B" in a process cannot have the same order.
So I need to know: -
a) how to specify some "unique"s in the model definition to fulfill the above requirements;
b) what uniqueness, if any, is automatically implied by a ManyToManyField?