How does determining subclass through hasattr trigger a db query in django's orm?
问题 For example, I am using multi-table inheritance for a class Node with sub-classes ConceptNode and DerivedNode. To determine the type of Node I am dealing with and distribute a function call down to the appropriate subclass, I often have to call hasattr like this: test_node = Node.objects.all()[0] if hasattr( test_node, "conceptnode"): test_node.conceptnode.myFunction() elif hasattr( test_node, "derivednode"): test_node.derivednode.myFunction() else: raise Exception("Not a valid type.") I've