0

我目前正在一个网站上工作,我想将 django-blog-zinnia 与 django-cms 一起使用。我必须通过外键将条目扩展到另一个,所以我按照百日草网站上的文档进行操作。

我写了 zinnia_extra/models.py:

from django.db import models
from zinnia.models_bases.entry import AbstractEntry


class AssociationBlog(AbstractEntry):
    association = models.ForeignKey("associations.Association",
                                blank=True,
                                default=None,
                                null=True,
                                related_name='news')

    def __str__(self):
        return 'AssociationBlog %s' % self.title

    class Meta(AbstractEntry.Meta):
        abstract = True

现在我来到了南部,这是文档不足的痛苦教训。经过几个小时在这里阅读了几个答案后,我发现设置南迁移模块的含义如下:

SOUTH_MIGRATION_MODULES = {
    'zinnia': 'zinnia_extra.migrations.zinnia',
}

之后我添加了

ZINNIA_ENTRY_BASE_MODEL = 'zinnia_extra.models.AssociationBlog'

我还构建了一个 zinnia_extra/admin.py:

from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from zinnia.models.entry import Entry
from zinnia.admin.entry import EntryAdmin


class AssociationBlogAdmin(EntryAdmin):

    fieldsets = ((_('Content'), {'fields': (
       ('title', 'status'), 'content', 'image', 'association')}),) + \
            EntryAdmin.fieldsets[1:]


admin.site.unregister(Entry)
admin.site.register(Entry, AssociationBlogAdmin)

(就像在文档中一样)

到settings.py。South 按预期工作,解决了实际上未解决的迁移错误。但我设法得到了。但我的额外字段不在管理区域。我四处搜索,发现我必须将额外的添加到 INSTALLED_APPS,所以它们现在看起来像这样:

INSTALLED_APPS = (
    ... ,
    'zinnia',
    'cmsplugin_zinnia',
    'zinnia_ckeditor',
    'zinnia_extra'
)

这实际上也可以在文档中找到(http://docs.django-blog-zinnia.com/en/latest/how-to/extending_entry_model.html)。

但现在我收到这样的错误:

Unhandled exception in thread started by <function wrapper at 0x1082ad9b0>
Traceback (most recent call last):
  File "/myproject/venv/lib/python2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper
    fn(*args, **kwargs)
  File "/myproject/venv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 101, in inner_run
    self.validate(display_num_errors=True)
  File "/myproject/venv/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
    num_errors = get_validation_errors(s, app)
  File "/myproject/venv/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/myproject/venv/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
    self._populate()
  File "/myproject/venv/lib/python2.7/site-packages/django/db/models/loading.py", line 75, in _populate
    self.load_app(app_name, True)
  File "/myproject/venv/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
    models = import_module('%s.models' % app_name)
  File "/myproject/venv/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/myproject/venv/lib/python2.7/site-packages/zinnia/models/__init__.py", line 4, in <module>
    from zinnia.models.entry import Entry
 File "/myproject/venv/lib/python2.7/site-packages/zinnia/models/entry.py", line 6, in <module>
    class Entry(load_model_class(ENTRY_BASE_MODEL)):
File: "/myproject/venv/lib/python2.7/site-packages/zinnia/models_bases/__init__.py", line 20, in load_model_class
    raise ImproperlyConfigured('%s cannot be imported' % model_path)
django.core.exceptions.ImproperlyConfigured: zinnia_extra.models.AssociationBlog cannot be imported

我现在已经搜索了几个小时,但我到了最后,不知道如何搜索这种错误类型。有人可以提供有关当前扩展工作流程的教程或帮助我解决此错误吗?

4

1 回答 1

0

看来问题是zinnia_extra模型的输入。

您可能需要添加此行:

from zinnia_extra.models import AssociationBlog

在某个文件中?

我不确定在 wich 文件中,但似乎 Django 无法导入您创建的类。

也许您需要将此导入添加到您的admin.py或 Django 使用的其他文件中AssociationBlog

我想到的另一个想法是:

  • 可能是您需要将zinnia_extra路径添加到 Python Path 吗?它是与您的项目相同的路径还是与 zinnia 应用程序相同的路径?
于 2014-11-12T12:19:42.203 回答