0

I wonder if it's possible to get all the parents classes from the inner Meta class.

class Abc(A,B,C):
   class Meta:
     # I wanna know A,B,C without explicitly listing them again. 
     # something like self.parents()

Edit : The actual problem..

Tastypie accessing fields from inherited models

I needed to list parents classes in meta.

class Abc(A,B,C):

   class Meta:
       list_of_fields_of_parents = A.fields + B.fields + C.fields
Community
  • 1
  • 1
eugene
  • 39,839
  • 68
  • 255
  • 489

1 Answers1

0

You can use Abc.__bases__. For example:

class Meta:
    list_of_fields_of_parents = [b.fields for b in Abc.__bases__]

Because this doesn't work for the Meta inside the Abc class, you can store your base classes in a list to keep things DRY:

abc_bases = [A, B, C]

class Abc(*bases):
    class Meta:
        list_of_fields_of_parents = [b.fields for b in abc_bases]
sk1p
  • 6,645
  • 30
  • 35
  • Oh, you are right. It's kind of a chicken/egg problem, because the `Abc` class is not completely constructed at that point. I'll edit my answer with another possibility... – sk1p Jan 06 '14 at 03:05