I have a couple of models like:
class Organization(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
....
class Customer(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
....
class Supplier(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
....
Each model have their own one or more users, I created a user model like this:
class User(AbstractBaseUser, PermissionsMixin):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
email_address = models.EmailField(max_length=255, unique=True)
name = models.CharField(max_length=255)
My question is how can I create a relationship between User and Organization, Customer, Supplier...? I found one solution like:
class User(AbstractBaseUser, PermissionsMixin):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
email_address = models.EmailField(max_length=255, unique=True)
name = models.CharField(max_length=255)
organization = models.ForeignKey(Organization)
customer = models.ForeignKey(Organization)
supplier = models.ForeignKey(Supplier)
Which I did not like to do because I have several models that have their users. Another way I found is GenericForeignKey Relationship but also not a very good solution. One of the reasons for this is I have more models to implement similar relationships which becomes very complicated. Can anyone suggest an elegant solution for this? Thanks in advance!