Answer the question
In order to leave comments, you need to log in
How to create an additional table for links between models?
There are two models Module (module) and ParentCategory (categories). they are not related to each other in any way.
class Modules(models.Model):
.....
class ParentCategory(models.Model):
....
pc_to_modules_assign = {
"Strategic Sourcing": ['COMMON S2P', 'COMMON SOURCING - SXM', 'SERVICES', 'SOURCING'],
"Supplier Management": ['COMMON S2P', 'COMMON SOURCING - SXM', 'SERVICES', 'SXM'],
"Spend Analytics": ['COMMON S2P', 'SERVICES', 'Spend Analytics'],
"Contract Management": ['COMMON S2P', 'SERVICES', 'CLM'],
"e-Procurement": ['COMMON S2P', 'SERVICES', 'eProcurement'],
"Invoice-to-Pay": ['COMMON S2P', 'SERVICES', 'I2P'],
"AP Automation": ['COMMON S2P', 'SERVICES', 'I2P', 'AP'],
"Strategic Procurement Technologies": ['COMMON S2P', 'COMMON SOURCING - SXM', 'SERVICES',
'SOURCING', 'SXM', 'Spend Analytics', 'CLM'],
"Procure-to-Pay": ['COMMON S2P', 'SERVICES', 'eProcurement', 'I2P'],
"Source-to-Pay": ['COMMON S2P', 'COMMON SOURCING - SXM', 'SERVICES',
'SOURCING', 'SXM', 'Spend Analytics', 'CLM', 'eProcurement', 'I2P']
}
Answer the question
In order to leave comments, you need to log in
To solve this problem, you need to use ManyToMany relation.
Add a line to the Modules class
parent_categories= models.ManyToManyField('ParentCategory', related_name='modules', through='ModuleParentCategory')
class ModuleParentCategory(models.Model):
module = models.ForeignKey(Module, on_delete=models.CASCADE)
parent_category = models.ForeignKey(ParentCategory, on_delete=models.CASCADE)
primary = models.BooleanField(default=False)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question