I cannot seem to find a way to add nodes of various polymorphic types to the same tree. Basically, I think I want a tree whose nodes are either a Company or Region, both inheriting from HierarchyNode which inherits from MP_Node
class HierarchyNode(MP_Node):
name = models.CharField(max_length=30)
class Company(HierarchyNode):
pass
class Region(HierarchyNode):
pass
Adding a Company root node is straight-forward
c1 = Company.add_root(name='Company 1')
But I can't seem to figure out how to add a Region as a child of c1
c1.add_child(name='Region 1') # adds a Company named Region 1
c1.add_child(Region(name='Region 1')) # isn't valid
Is there a way to do this? Does the API not allow this because it is a bad idea? Is there a more appropriate way to model this concept? Alternatively, I suppose I could have a tree of HierarchyNodes which have a one-to-one relationship to the Company/Region types.