Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 organizations are as clean as this. Some Organizations will have dancers, for instance (a dance troup), plus any number of generic Individuals 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 Individuals to the Organization through a many to many relationship, create a Job class mapping Individuals 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 Teachers 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?


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)
share|improve this question

closed as off topic by Jim G., Matthieu, Walter, Dynamic, Yusubov Sep 20 '12 at 11:15

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 1 down vote accepted

As always with business analysis patterns: check out Martin Fowler: , more specifically his catalog of Patterns of Enterprise Application Architecture: and his further development of those:

For dealing with roles he has a dedicated pdf around (probably taken from his book Analysis Design Patterns). IIRC in the book his examples were centered around hospitals, physicians and contracts (or rights to practice in a hospital), but you can get a lot of inspiration from his writings. PDF: (It may take some time to load, the site seems very slow at the moment I write this).

share|improve this answer
Thanks. That roles document definitely looks helpful. I think I may have come up with a good solution, but I'll check it against what I read in this paper. Thanks again – user25791 May 21 '12 at 3:40