This is how I might do it:
from django.db import models
from django.contrib.auth.models import User
class Shareholder(models.Model):
name = models.CharField(max_length=128)
user = models.OneToOneField(to=User, related_name='shareholder_profile')
def __str__(self):
return self.name
class Company(models.Model):
name = models.CharField(max_length=128)
shareholders = models.ManyToManyField(Shareholder, through='Shareholding')
def __str__(self):
return self.name
class Shareholding(models.Model):
shareholder = models.ForeignKey(Shareholder, on_delete=models.CASCADE)
company = models.ForeignKey(Company, on_delete=models.CASCADE)
date_shares_purchased = models.DateField()
number_of_shares = models.PositiveIntegerField()
Instead of using the User model directly, I would create a Shareholder model with a one-to-one relationship with the User. Then I would create the many-to-many relationship between the Shareholders and Company with a Shareholding intermediate model.
This technique of extending the User model using a one-to-one relationship with a Profile model is described in more detail in the original docs and on this article