views:

110

answers:

1

If a django model is made abstract, like below, is there a way to inspect the class to determine that it is abstract?

class MyModel(models.Model):
  class Meta:
    abstract = True

I would expect that I could examine MyModel.Meta.abstract, but according to Django docs:

Django does make one adjustment to the Meta class of an abstract base class: before installing the Meta attribute, it sets abstract=False. This means that children of abstract base classes don't automatically become abstract classes themselves.

Any ideas? Thanks!

+5  A: 

You can instantiate MyModel and then check ._meta.abstract.

So in code:

m = MyModel()
print m._meta.abstract
sheats
I didn't spot that in dir(MyModel), but it's there. Thanks very much.
Nagyman
If you haven't looked into iPython I would strongly suggest it. It is very useful for playing around and finding out these things since it offers auto-completion. That's how I found this one =)
sheats