1👍
✅
You can use a custom through
model to add details to the Many-to-many relation like this:
class CustomUser(AbstractUser):
pass
class Project(models.Model):
users = models.ManyToManyField(CustomUser, through='ProjectDetails')
class Permission(models.Model):
pass
class ProjectDetails(models.Model):
user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
project = models.ForeignKey(Project, on_delete=models.CASCADE)
permission = models.ForeignKey(Permission, on_delete=models.CASCADE)
This way, each user for a project can be assigned a certain permission (per project). You can also add more details about a certain user’s involvement in a project. For example, when they started in a project.
If you want to learn more, you can have a read here.
Source:stackexchange.com