I have various component models, all with unique attributes:
power = IntegerField()
diameter = IntegerField()
flow_rate = exampleField()
I need to query these based on component requirements to select the suitable motor, valve, pump etc and then ‘assign’ these to a ‘configuration’:
configuration = ForeignKey(Configuration)
component = ForeignKey(Motor/Valve/Pump … etc)
quantity = IntegerField()
I later require to be able to access the component attributes from Assign. Example:-
assign = Assign.objects.get(id=1)
I also require to select an assign_set via configure and then access the component attributes via those assigns. In pseudo code:
configured = Configure.objects.get(id=1)
motor = configured.assign_set.filter(component__classtype = motor)
My problem being that I cannot have one component foreign key to an unknown model class in assign.
I have tried generic foreign key … it’s messy and I don’t think it will scale well; I could be wrong on that. I’ve also create a component model and then motor, valve etc inherit from that … the foreign key to component allows me to get component, but not the subclass attributes like power for motor or diameter for valve.
I would really appreciate anyone being able to help me meet these requirements, or advising the best way to achieve something close. It would be great to keep the SQL behind any solution concise and fast because the intention is for this to scale