I am creating an investor object. Investors can be people or companies.
How can I create a model object that could represent either of these types in django?
Here are a few ways I was thinking:
1. Having two non required foreign keys:
class Investor(models.Model):
company = models.ForeignKey('companies.Company',on_delete=models.CASCADE, blank=True, null=True)
customer = models.ForeignKey('accounts.Customer',on_delete=models.CASCADE, blank=True, null=True)
investor_name = models.CharField(max_length=255)
2. Using a generic relation:
class TaggedItem(models.Model):
investor_name = models.CharField(max_length=255)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
3. An abstract model that is inherited by both customer and company
class Entity(models.Model)
class Customer(Entity)
Class Company(Entity)
What is the most architecturally sound route to go which will not cause me a lot of problems down the line?