Single 'through' model for multiple m2m fields

I'm trying to extend and refactor some legacy project. I have some set of models which represent "hardware" of some assebled device. Something like :

class ComponentA(models.Model)
    brand = models.CharField()
    model = models.CharField()
    category = models.ForeignKey(Category)

class Configuration(models.Model):
    component_a = ForeignKey(ComponentA)
    component_b = ForeignKey(ComponentB)
    component_n...

class Device(models.Model):
    configuration = models.ForeignKey(Configuration)

The goal is to extent ComponentA...ComponentN with Many2Many field which suppose to contain some extra parts and those parts quantity it consist of. However I found it weird to have through model for each Component model. All of the Component models shoud have a quantity for further statistic/calculations. Is there is some "clean" approach for implementation such a functionality?

Вернуться на верх