0

i' ve a Django model object. Is there any way to get to know (in code of course) where does it inherit from?

As an example:

class CDate(models.Models):
    class Meta:
        abstract = True
    active = models.BooleanField()

class SWT(CDate):
    name = models.CharField(max_length=32)

class RealObj(SWT):
    code = models.CharField(max_length=32)

. In this case of a RealObj i' d like to get to know that it inhertis from SWT. How can i do that?

Thanks.

Gahan
  • 4,075
  • 4
  • 24
  • 44
user2194805
  • 1,201
  • 1
  • 17
  • 35
  • Possible duplicate of [List all base classes in a hierarchy of given class?](https://stackoverflow.com/questions/1401661/list-all-base-classes-in-a-hierarchy-of-given-class) – Mike Scotty May 08 '18 at 09:55
  • Why would you need to know this? What's the actual use case? – Daniel Roseman May 08 '18 at 09:57
  • The actual usecase is to move part of a django application from one server to another (i mean the database) and to get the overlapping IDs, but as there' re more than 100 objects, it' s good to know its type, so i can write some prechecks. – user2194805 May 08 '18 at 10:00
  • Thanks, inspect can be used for my goal. With inspect.getmro it' s pretty trivial to achieve my goal. – user2194805 May 08 '18 at 10:01
  • It looks like a similar answer exists here https://stackoverflow.com/questions/10091957/get-parent-class-name – codeKashmir May 08 '18 at 10:04

0 Answers0