Possible Duplicate:
get python class parent(s)
I have a:
class Animal(models.Model):
pass
class Cat(Aminal):
pass
class StreetCat(Cat):
pass
How can I find out the model a model inherits from?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can get the direct superclass in python through
__base____bases__will get you a tuple of all parent classes if you have multiple base classesclass Foo(A, B)Update thanks to OP: the following django method does not retrieve abstract base classes, as technically these are internal use methods for storing the foreign keys that tie each inherited model to their parents. Be warned!
Django also indirectly provides some helpers for inherited models which are shortcuts for the pure python methods of traversing the superclasses.
InheritedClass.parentsis an ordered dictionary of all parents, so the following would work to get the upper most parent if you wanted:You could also use a non django related method, something like