Question

I'm having a problem with get_model for Django. get_model works with every model I'm trying to get except for the BlogPost model from Mezzanine.

I've tried:

model = get_model('mezzanine.blog', 'BlogPost')
model = get_model('mezzanine', 'BlogPost')

Those lines return None. I have a feeling that I am not using the proper app_label for the first argument but I am not sure as to what the proper app_label is. Importing it normally works.

from mezzanine.blog.models import BlogPost

I looked at the source code for Mezzanine and BlogPost is in the mezzanine.blog app so I assumed that the app_label should be mezzanine.blog.

Any help is greatly appreciated!

Was it helpful?

Solution

Django's get_model uses Django's app name + object name convention, where the app name is immediate package name, in this case blog. Try:

model = get_model('blog', 'BlogPost')

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top