Django FeinCMS 和页面扩展问题

发布于 2024-10-21 19:15:40 字数 2026 浏览 1 评论 0原文

我正在尝试页面扩展 和 FeinCMS 1.2.1。

我想创建这个简单的页面扩展:

from django.db import models

def register(cls, admin_cls):
    cls.add_to_class(models.TextField())

但我不断收到此错误:

AttributeError: 'module' object has no attribute 'TextField'

包含扩展的包称为 dev.extensions 和模块 categories,我添加了将其添加到 Python 路径,并使用 Page.register_extensions('dev.extensions.categories') 注册扩展。

我想知道我做错了什么,请帮忙。

完整的堆栈跟踪如下。

c:\sandbox\projects\feindev>python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 13, in <module>
    execute_manager(settings)
  File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 436, in execute_m
anager
    setup_environ(settings_mod)
  File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 419, in setup_env
iron
    project_module = import_module(project_name)
  File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
  File "c:\sandbox\projects\feindev\..\fein
dev\__init__.py", line 52, in <module>
    Page.register_extensions('dev.extensions.types')
  File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\models.py", line 270, in register_extensions
    cls.register_extension(fn)
  File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\module\page\models.py", line 564, in register_exten
sion
    register_fn(cls, PageAdmin)
  File "c:\sandbox\projects\feindev\dev\ext
ensions\types\__init__.py", line 4, in register
    cls.add_to_class(models.TextField())
AttributeError: 'module' object has no attribute 'TextField'

I'm experimenting with Page extensions and FeinCMS 1.2.1.

I'd like to create this simple page extension:

from django.db import models

def register(cls, admin_cls):
    cls.add_to_class(models.TextField())

but I keep getting this error:

AttributeError: 'module' object has no attribute 'TextField'

The package containing the extension is called dev.extensions and the module categories, I have added it to the Python path and the extension is registered with Page.register_extensions('dev.extensions.categories').

I'm wondering what I'm doing wrong, please help.

The complete stacktrace follows.

c:\sandbox\projects\feindev>python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 13, in <module>
    execute_manager(settings)
  File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 436, in execute_m
anager
    setup_environ(settings_mod)
  File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 419, in setup_env
iron
    project_module = import_module(project_name)
  File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
  File "c:\sandbox\projects\feindev\..\fein
dev\__init__.py", line 52, in <module>
    Page.register_extensions('dev.extensions.types')
  File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\models.py", line 270, in register_extensions
    cls.register_extension(fn)
  File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\module\page\models.py", line 564, in register_exten
sion
    register_fn(cls, PageAdmin)
  File "c:\sandbox\projects\feindev\dev\ext
ensions\types\__init__.py", line 4, in register
    cls.add_to_class(models.TextField())
AttributeError: 'module' object has no attribute 'TextField'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

活泼老夫 2024-10-28 19:15:40

在您的注册函数运行之前,也许模型会被重新分配给另一个模块?

尝试将您的代码更改为:

from django.db import models as django_models

def register(cls, admin_cls):
    cls.add_to_class('field_name_here', django_models.TextField())

Maybe models is getting reassigned somewhere to another module before your register function gets run?

Try changing your code to this:

from django.db import models as django_models

def register(cls, admin_cls):
    cls.add_to_class('field_name_here', django_models.TextField())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文