Hello Ken,
Thanks for your quick answer.
I’ll try to be more specific (model classes in the bottom)
For the RentContract
- the contractor can be one or multiple Person object AND / OR one or multiple Company object
- idem for the contractant
there is no difference between the contractor and the contractant. Both can be one or multiple Person OR /AND one or mulptiple Company.
I used these terms (contractant and contractor) just to specify who are the two parts of the contract, like a lessor and a lessee for a flat renting contract. If I continue using the real estate example here, in The RentContract the Lessee could bet composed of two Persons and one Company and the lessor just one Company. So it could be like having a ‘normal’ Many to Many relationship but with the sum of the objects from Person.objects.all() + Company.objects.all().
there is no required association between a Person and a Company (even if a Person could be associated with a Company)
I hope I did clarify…
class Company(models.Model):
name = models.CharField(max_length=100)
legal_form = models.CharField(max_length=35, default=None, blank=True, null=True)
address = models.ForeignKey(Address, on_delete=models.PROTECT, default=None, null=True, blank=True)
vat_number = models.CharField(max_length=100, default=None, null=True, blank=True)
registration_number = models.CharField(max_length=100, default=None, null=True, blank=True)
phone = models.CharField(max_length=50, default=None, blank=True, null=True)
email = models.EmailField(default=None, blank=True, null=True)
internal_uuid = models.CharField(max_length=35, default=None, null=True, blank=True)
timestamp_updated = models.DateTimeField(auto_now=True)
timestamp_created = models.DateField(auto_now_add=True)
comment = models.TextField(default=None, blank=True, null=True)
note = models.TextField(default=None, blank=True, null=True)
def __str__(self):
return f"{self.name} {self.legal_form}"
class Meta:
verbose_name_plural = 'Companies'
ordering = ('name',)
class Person(models.Model):
firstname = models.CharField(max_length=100)
lastname = models.CharField(max_length=100)
address = models.ForeignKey(Address, on_delete=models.PROTECT, default=None, null=True, blank=True)
company = models.ManyToManyField(Company, through=‘Position’, default=None, blank=True)
phone = models.CharField(max_length=50, default=None, blank=True, null=True)
email = models.EmailField(default=None, blank=True, null=True)
timestamp_updated = models.DateTimeField(auto_now=True)
timestamp_created = models.DateField(auto_now_add=True)
comment = models.TextField(default=None, blank=True, null=True)
note = models.TextField(default=None, blank=True, null=True)
def __str__(self):
return f"{self.lastname} {self.firstname}"
class Meta:
ordering = ('lastname',)