I have a function, get_priority()
, which sorts through all objects in a parent class (Chunk) to get the highest 'priority' object. Now I want to get the related subclass object to the superclass object.
The Django docs on Multi-Table Inheritance show that I can do this by using the lowercase name of the subclass. For example, if the subclass was Concept I could do the following:
chunk = get_priority(Chunk.objects.all())
chunk.concept
However, the subclass could be Concept, Code, Formula or Problem. Is the only way to approach this to use try/except for each subclass, e.g.:
chunk = get_priority(Chunk.objects.all())
try:
object = chunk.concept
except:
pass
try:
object = chunk.code
except:
pass
# etc.