16👍
✅
You can instantiate MyModel and then check ._meta.abstract.
So in code:
m = MyModel()
print m._meta.abstract
3👍
I’d like to point out that you don’t need to instantiate a model to check if it’s abstract – Django models inherit an actual metaclass that adds _meta on class instantiation.
So, similarly to @sheats’s code, try
from django.db.models import Model
class MyModel(Model):
pass
print MyModel._meta.abstract
Or, for a positive example
from django.db.models import Model
class MyModel(Model):
class Meta(object):
abstract = True
print MyModel._meta.abstract
Of course, this also works for built-in models and anything inheriting from Django’s Model.
from django.contrib.auth.models import User
print User._meta.abstract
- Add dynamic field to django admin model form
- How to get django queryset results with formatted datetime field
- Django translate model choices
- How to generate an AccessToken programmatically in Django?
Source:stackexchange.com