Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

LookupError when using HTMLField in a custom user model #468

@danielsamuels

Description

@danielsamuels

I've got a custom user model in my project, but it appears to be the case that if I attempt to use a HTMLField within it (for example, if I want a 'biography' field), it causes a LookupError because utils.py imports cms.models.CMSPlugin which eventually tries to get the custom user model which doesn't exist yet.

Here's a simple model which should reproduce the error:

from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from djangocms_text_ckeditor.fields import HTMLField


class Individual(AbstractBaseUser, PermissionsMixin):

    biography = HTMLField(
        'professional biography',
        blank=True,
        null=True,
    )

and here's the relevant part of the traceback:

  File "redacted/apps/individuals/models.py", line 4, in <module>
    from djangocms_text_ckeditor.fields import HTMLField
  File ".venv/lib/python3.6/site-packages/djangocms_text_ckeditor/fields.py", line 7, in <module>
    from .html import clean_html
  File ".venv/lib/python3.6/site-packages/djangocms_text_ckeditor/html.py", line 14, in <module>
    from .utils import plugin_to_tag
  File ".venv/lib/python3.6/site-packages/djangocms_text_ckeditor/utils.py", line 8, in <module>
    from cms.models import CMSPlugin
  File ".venv/lib/python3.6/site-packages/cms/models/__init__.py", line 4, in <module>
    from .permissionmodels import *  # nopyflakes
  File ".venv/lib/python3.6/site-packages/cms/models/permissionmodels.py", line 21, in <module>
    User = apps.get_registered_model(user_app_name, user_model_name)
  File ".venv/lib/python3.6/site-packages/django/apps/registry.py", line 268, in get_registered_model
    "Model '%s.%s' not registered." % (app_label, model_name))
LookupError: Model 'individuals.Individual' not registered.

The order of apps in my INSTALLED_APPS is:

[
    'redacted.apps.individuals',
    'cms',
    'djangocms_text_ckeditor',
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions