百日菊和千篇一律的姜戈集成中的用户模型问题



首先我的设置:

  • Linux Mint 18.2
  • 百日菊 0.20
  • 姜戈 1.9.9
  • 千篇一律的姜戈 1.9.9
  • 蟒蛇 3.5.2

我使用 1.9.9 版使用 cookiecutter-django 从头开始创建了一个项目,一旦在 zinnia 文档中建议使用 django <2.0。我只是:

git checkout 1.9.9

我按照文档进行操作,项目运行正常。但是,添加百日菊后,我无法迁移。这是我的file config/settings/common.py

THIRD_PARTY_APPS = (
'crispy_forms',  # Form layouts
'allauth',  # registration
'allauth.account',  # registration
'allauth.socialaccount',  # registration
'mptt',
'tagging',
'zinnia',   
)
TEMPLATES = [
{
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
'DIRS': [
str(APPS_DIR.path('templates')),
],
'OPTIONS': {
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
'debug': DEBUG,
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
# https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
# Your stuff: custom template context processors go here
'zinnia.context_processors.version',  # Optional
],
},
},
]

confi/urls.py

urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name='home'),
url(r'^about/$', TemplateView.as_view(template_name='pages/about.html'), name='about'),
# Django Admin, use {% url 'admin:index' %}
url(settings.ADMIN_URL, include(admin.site.urls)),
# User management
url(r'^users/', include('rmining.users.urls', namespace='users')),
url(r'^accounts/', include('allauth.urls')),
# Your stuff: custom urls includes go here
url(r'^weblog/', include('zinnia.urls')),
url(r'^comments/', include('django_comments.urls')),

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

当我运行python manage.py migrate时,出现以下错误:

"Model '%s.%s' not registered." % (app_label, model_name))
LookupError: Model 'users.User' not registered.

我该如何解决这个问题?

我发现这是Zinnia加载用户模型的"错误"。

在百日菊/模特/作者.py:

def safe_get_user_model():
"""
Safe loading of the User model, customized or not.
"""
user_app, user_model = settings.AUTH_USER_MODEL.split('.')
return apps.get_registered_model(user_app, user_model)

我将其更改为:

[...]
from django.contrib.auth import get_user_model
[...]
def safe_get_user_model():
"""
Safe loading of the User model, customized or not.
"""
# user_app, user_model = settings.AUTH_USER_MODEL.split('.')
# return apps.get_registered_model(user_app, user_model)
return get_user_model()

并完美运行。

我正在尝试在全新安装中对其进行测试。如果它有效,我将用它发出拉取请求。

最新更新