How do you map members and their responsibilities to an organization? [closed]
https://softwareengineering.stackexchange.com/questions/149327
-
04-11-2019 - |
Question
I'm working on a Django project that tracks arts-related activities, and I'm stuck on the human-resources part of things.
(code below) I have a class Ensemble
that subclasses Organization
. Organization
only has one important field, name
. Ensemble
has another field, players
(a many to many relationship). A player is a Performer
which has two foreign key fields, individual
and instrument
. The idea is that a performer is any individual on a particular instrument--so, e.g., I can be one individual that can be two performers: one on guitar, the other on bass.
The problem is that not all organization
s are as clean as this. Some Organization
s will have dancers, for instance (a dance troup), plus any number of generic Individual
s who do any number of specific tasks not tracked as a specific class (like Performer
). So at first I was thinking it would be best to just map Individual
s to the Organization
through a many to many relationship, create a Job
class mapping Individual
s to a JobCode
class (which might include a row with something like 'performer'), but that doesn't work well if for instance you want to keep track of which instrument a performer plays for that particular ensemble, or if they play multiple instruments, I would like to be able to make that explicit. That's why the Ensemble::players
relationship made sense to me.
So it seems I have an Organization
class that will never truly be more than abstract, but I still need to be able to track what type of job an individual
does for an Organization
. Ensemble
only makes sense for mapping Performers
to an Organization
, but what about Teacher
s in a School
? Again, I would like to be able to make it explicit that a bassoon player is teaching bassoon at the school, and not clarinet (even though they might play both). So I can't just map the Individual
to the School
organization, right?
Also, this seems like it would be a common problem. Is there a conventional way of dealing with these kinds of relationships? What is the most effective?
Code:
class Individual(models.Model):
surname = models.CharField(max_length=255)
name = models.CharField(max_length=255)
prefix = models.ForeignKey(Prefix, blank=True, null=True)
suffix = models.ManyToManyField(Suffix, blank=True)
date_of_birth = models.DateField(null=True, blank=True)
phone_numbers = models.ManyToManyField(PhoneNumber, blank=True)
addresses = models.ManyToManyField(Address, blank=True)
user = models.OneToOneField(User, blank=True, null=True)
class Performer(models.Model):
individual = models.ForeignKey(Individual)
instrument = models.ForeignKey(Instrument)
class Organization(models.Model):
name = models.CharField(max_length=255)
founded = models.DateField()
tags = TaggableManager(blank=True)
media = models.ManyToManyField(Upload, blank=True)
class Ensemble(Organization):
players = models.ManyToManyField(Performer)
No correct solution