I have the following models:
class Ensemble(Group):
name = models.CharField(max_length=100, null=True, blank=True)
instrumentation = models.ForeignKey(Instrumentation -> Instrument, verbose_name=_('part'), related_name='ensemble_member', null=True, blank=True, on_delete=models.PROTECT)
class EnsembleMember(models.Model):
person = models.ForeignKey(Person, verbose_name=_('member'), on_delete=models.PROTECT)
instrument ???? = models.ForeignKey(Instrumentation, verbose_name=_('part'), related_name='ensemble_member', null=True, blank=True, on_delete=models.PROTECT) //This is the line in question
ensemble = models.ForeignKey(Ensemble, verbose_name=_('ensemble'), related_name='ensemble_member', on_delete=models.PROTECT)
class Instrumentation(models.Model):
name = models.CharField(max_length=100, null=True, blank=True)
class Instrument(MPTTModel):
name = models.CharField(max_length=100, null=True, blank=True)
category = models.CharField(max_length=100, null=True, blank=True)
instrumentation = models.ManyToManyField(Instrumentation, verbose_name=_('instrumentation'), related_name='instrument', blank=True)
I would like to be able to able to link EnsembleMembers to only the instruments available in instrumentation under Ensemble. How would I create this ForeignKey relationship.
For example:
There are three instruments: Violin, Cello, and Piano
An instance of instrumentation with this three instruments is called "Piano Trio".
An ensemble called the "Beaux Arts Trio" is linked to the instrumentation "Piano Trio".
"Menahem Pressler" is an Ensemble Member and the pianist in the "Beaux Arts Trio".
I want to link this instrument to the "Piano". Piano is an allowable instrument to be linked because it is in the instrumentation linked to the Ensemble. How do I setup this last connection in the EnsembleMember model?
I'd like to have the following connections before Ensemble and Instrumentation.
Piano Trio (Instrumentation) --> Beaux Arts Trio (Ensemble)
^ ^
| |
| |
Piano (Instrument) --> Menahem Pressler (pianist, Ensemble Member)
Violin (Instrument) --> Daniel Guilet (violinist, Ensemble Member)
Cello (Instrument) --> Bernard Greenhouse (cellist, Ensemble Member)