문제

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!

도움이 되었습니까?

해결책

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')

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top