There is a shorcut get_model.
from django.db.models import get_model
And here is his signature:
def get_model(self, app_label, model_name, seed_cache=True):
And here is how you can use it:
>>> from django.db.models import get_model >>> model = 'amavisd.models.Domain' >>> app_label, _, class_name = model.split('.') >>> model = get_model(app_label, class_name) >>> type(model) class 'django.db.models.base.ModelBase'
For django 1.8+ you can use the following code
>>> from django.apps import apps >>> apps.get_model('shop', 'Product') <class 'shop.models.Product'> >>>
source share