Malte
Malte

Reputation: 347

Are django-CMS and cookiecutter-django incompatible?

I just tried to port my Django-CMS project into Django Cookiecutter (cookiecutter-django) in order to get it to run in Docker.

It seems Django-CMS is using the default Django user model and Cookie-Cutter is using a custom model (from allauth?).

I found this https://github.com/pydanny/cookiecutter-django/pull/248 thread which suggests changing the order in which the apps are loaded but that doesn't cut the mustard.

Are Django-CMS and Cookiecutter at odds with each other?

ADDITION: Running Django 2.2.7 and django-cms 3.7.2

EDIT: The error message/traceback when I run

$ docker-compose -f local.yml up
...
postgres_1  | 2020-04-22 13:58:12.315 UTC [1] LOG:  database system is ready to accept connections
django_1    | PostgreSQL is available
django_1    | Traceback (most recent call last):
django_1    |   File "manage.py", line 30, in <module>
django_1    |     execute_from_command_line(sys.argv)
django_1    |   File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
django_1    |     utility.execute()
django_1    |   File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
django_1    |     django.setup()
django_1    |   File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
django_1    |     apps.populate(settings.INSTALLED_APPS)
django_1    |   File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
django_1    |     app_config.import_models()
django_1    |   File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
django_1    |     self.models_module = import_module(models_module_name)
django_1    |   File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
django_1    |     return _bootstrap._gcd_import(name[level:], package, level)
django_1    |   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
django_1    |   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
django_1    |   File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
django_1    |   File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
django_1    |   File "<frozen importlib._bootstrap_external>", line 728, in exec_module
django_1    |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
django_1    |   File "/usr/local/lib/python3.7/site-packages/cms/models/__init__.py", line 4, in <module>
django_1    |     from .permissionmodels import *  # nopyflakes
django_1    |   File "/usr/local/lib/python3.7/site-packages/cms/models/permissionmodels.py", line 21, in <module>
django_1    |     User = apps.get_registered_model(user_app_name, user_model_name)
django_1    |   File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 273, in get_registered_model
django_1    |     "Model '%s.%s' not registered." % (app_label, model_name))
django_1    | LookupError: Model 'users.User' not registered.

So I kept fiddling with the order that the apps are loaded in but to no avail.

Upvotes: 0

Views: 304

Answers (1)

Malte
Malte

Reputation: 347

It turns out, the two are compatible. I tried the latest version of the djangocms-installer and manually merged that with the latest cookiecutter-django base.

In the cookiecutter-django's base.py (settings)

...

LOCAL_APPS = [
    "mysite.users.apps.UsersConfig",
]

DJANGO_CMS_APPS = [
    "cms",
    "menus",
    "sekizai",
    "treebeard",
    "djangocms_text_ckeditor",
    "filer",
    "easy_thumbnails",
    "djangocms_bootstrap4",
    "djangocms_bootstrap4.contrib.bootstrap4_alerts",
    "djangocms_bootstrap4.contrib.bootstrap4_badge",
    "djangocms_bootstrap4.contrib.bootstrap4_card",
    "djangocms_bootstrap4.contrib.bootstrap4_carousel",
    "djangocms_bootstrap4.contrib.bootstrap4_collapse",
    "djangocms_bootstrap4.contrib.bootstrap4_content",
    "djangocms_bootstrap4.contrib.bootstrap4_grid",
    "djangocms_bootstrap4.contrib.bootstrap4_jumbotron",
    "djangocms_bootstrap4.contrib.bootstrap4_link",
    "djangocms_bootstrap4.contrib.bootstrap4_listgroup",
    "djangocms_bootstrap4.contrib.bootstrap4_media",
    "djangocms_bootstrap4.contrib.bootstrap4_picture",
    "djangocms_bootstrap4.contrib.bootstrap4_tabs",
    "djangocms_bootstrap4.contrib.bootstrap4_utilities",
    "djangocms_file",
    "djangocms_icon",
    "djangocms_link",
    "djangocms_picture",
    "djangocms_style",
    "djangocms_snippet",
    "djangocms_googlemap",
    "djangocms_video",
    "mysite",
]

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS + DJANGO_CMS_APPS

I created another stack for Django-CMS apps. The order of the installed apps is important. So LOCAL_APPS has to be loaded BEFORE the DJANGO_CMS_APPS.

I tried the same in previous versions and still have no idea why it failed there. Hope this helps somehow.

Upvotes: 1

Related Questions