简体   繁体   English

在Django 1.7迁移中获取名称分隔的模型

[英]Getting name spaced models inside Django 1.7 migrations

I'm using django-allauth as part of a new project, and I'm trying to make a migration where I set up the initial authentication keys for the social apps. 我将django-allauth用作新项目的一部分,并且尝试进行迁移,在该迁移中我为社交应用设置了初始身份验证密钥。

To do this I need to access a model that is under a namespace of 为此,我需要访问位于以下名称空间下的模型

'allauth.socialaccount', which I also have in my settings.py 'allauth.socialaccount',我在settings.py中也有

However, when I attempt to do the following; 但是,当我尝试执行以下操作时;

SocialApp = apps.get_model('allauth.socialaccount', 'socialapp')

I end up with Django telling me the app with that name doesn't exist. 我最终以Django告诉我该名称的应用程序不存在。

I have also tried pretty much every combination of 'allauth', 'socialaccount' and, 'socialapp' 我还尝试了“ allauth”,“ socialaccount”和“ socialapp”的每种组合

I'm pretty much stuck at this point. 在这一点上,我几乎陷入了困境。

For namespaced models you need to use the final part of the dotted path as the app_label . 对于命名空间模型,您需要将虚线路径的最后一部分用作app_label For allauth.socialaccount that is socialaccount . 对于allauth.socialaccount ,这是socialaccount

>>> apps.get_model('socialaccount', 'SocialApp')
allauth.socialaccount.models.SocialApp

Also don't forget to reference the a migration from the socialaccount app as a dependency, otherwise it won't be available: 另外,不要忘了将来自socialaccount应用程序的迁移引用为依赖项,否则它将不可用:

dependencies = [
    # ('some_app', 'XXXX_some_pre-requisite_migration'),
    ('socialaccount', '0001_initial'),
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM