Answer the question
In order to leave comments, you need to log in
Selecting relationships between tables in a database?
Prompt on correctness of a choice of architecture of a DB under the task. The meaning is the following
There is a Vendors model - in fact it is a commercial organization, there can be many of them
class Vendors(models.Model):
name...
country ....
class Modules(models.Model):
MODULES_NAME = (
("Sourcing", "Sourcing"), ("SA", "SA"),
("SXM", "SXM"), ("CLM", "CLM"),
.....
)
module_name = models.CharField(max_length=50, choices=MODULES_NAME)
active = models.BooleanField(default=True)
class VendorModule(models.Model):
vendor = models.OneToOneField('Vendors', on_delete=models.CASCADE, primary_key=True)
active = models.BooleanField(default=True)
class Element(models.Model):
info1...
info2.....
....
Answer the question
In order to leave comments, you need to log in
I propose the following scheme:
class Vendor(models.Model):
...
class Module(models.Model):
MODULES_NAME = (
("Sourcing", "Sourcing"), ("SA", "SA"),
("SXM", "SXM"), ("CLM", "CLM"),
...
)
name = models.CharField(max_length=50, choices=MODULES_NAME)
is_active = models.BooleanField(default=True)
class VendorModule(models.Model):
vendor = models.ForeignKey(Vendor, on_delete=models.CASCADE)
module = models.ForeignKey(Module, on_delete=models.CASCADE)
is_active = models.BooleanField(default=True)
info1 = models.TextField(max_length=500)
info2 = models.TextField(max_length=500)
VendorModule
- in fact, this is a many-to-many connection with the ability to save additional information. The purpose of the model Element
is not clear, so additional information is removed in VendorModule
. But if you think that this is not enough, then you can do this:class Element(models.Model):
vendormodule = models.ForeignKey(VendorModule, on_delete=models.CASCADE)
info1 = models.TextField(max_length=500)
info2 = models.TextField(max_length=500)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question