I just finished coding a django app that helps music producers coordinate projects and I am trying to solve a small problem I am facing: For every music project, users are assigned specific roles (sound tech, drummer, production manager et cetera) and depending on their role, they should be able to see/do only some things within the project.
For example, the production manager should be able to see a project's budget and the drummer shouldn't; but they both should be able to see the location of the next recording session.
One thing to notice is that what some roles might be allowed to see might change from one project to the other. That is to say that it's possible that a Drummer should have visibility over the budget on one project and not on another (so I can't fix permissions based on the role and I need something more fluid where I can add and remove roles).
To make it simpler, we can consider that currently I only have the following models (on top of basic user model)
class JobProject(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
client = models.ManyToManyField(Company, related_name='client_company', blank=True)
title = models.CharField(max_length=40)
number = models.CharField(max_length=40, null=True)
class JobPosition(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
title = models.ForeignKey(Title, on_delete=models.CASCADE)
city = models.ForeignKey(City, on_delete=models.CASCADE)
rate = models.CharField(max_length=20)
jobproject = models.ForeignKey(JobProject, related_name='crew', on_delete=models.CASCADE, blank=True, null=True)
class Event(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
date = models.DateField(blank=True, null=True)
event_name = models.ForeignKey(EventName, blank=True, on_delete=models.CASCADE, related_name='events', null=True)
project = models.ForeignKey(JobProject, blank=True, on_delete=models.CASCADE, related_name='jobproject_events', null=True)
...
class dept_budget(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(choices=DEPARTMENTS, max_length=55)
budget = models.CharField(max_length=250)
jobproject = models.ForeignKey(JobProject, on_delete=models.CASCADE)