Search code examples
pythondjangocontent-management-systemfeincms

Django FeinCMS and page extensions issue


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'

Solution

  • 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())