given a string identifying a Django model I have to obtain the associated object of type <class 'django.db.models.base.ModelBase'> or None.
I'm going to show my solution, that works fine but looks ugly. I'd be glad to know if there are better options to obtain the same result. Does something like a Django shortcut exist for that? Thanks.
>>> from django.utils.importlib import import_module
>>> model = 'sandbox.models.Category'
>>> full_name = model.split(".")
>>> module_name = ".".join(full_name[:-1])
>>> class_name = full_name[-1]
>>> model = getattr(import_module(module_name), class_name, None)
>>> type(model)
<class 'django.db.models.base.ModelBase'>