1

First of all my setup:

  • Linux Mint 18.2
  • Zinnia 0.20
  • Django 1.9.9
  • cookiecutter-django 1.9.9
  • Python 3.5.2

I have created a project from scratch with cookiecutter-django, using version 1.9.9, once that in zinnia docs it's recommended to use django < 2.0. I simply:

git checkout 1.9.9

I followed the docs and the project is running ok. HOWEVER, after add zinnia I'm unable to migrate. Here my file config/settings/common.py

THIRD_PARTY_APPS = (
    'crispy_forms',  # Form layouts
    'allauth',  # registration
    'allauth.account',  # registration
    'allauth.socialaccount',  # registration
    'mptt',
    'tagging',
    'zinnia',   
)

TEMPLATES = [
    {
        # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
        'DIRS': [
            str(APPS_DIR.path('templates')),
        ],
        'OPTIONS': {
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
            'debug': DEBUG,
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
            # https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ],
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
                # Your stuff: custom template context processors go here
                'zinnia.context_processors.version',  # Optional
            ],
        },
    },
]

and confi/urls.py

urlpatterns = [
    url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name='home'),
    url(r'^about/$', TemplateView.as_view(template_name='pages/about.html'), name='about'),

    # Django Admin, use {% url 'admin:index' %}
    url(settings.ADMIN_URL, include(admin.site.urls)),

    # User management
    url(r'^users/', include('rmining.users.urls', namespace='users')),
    url(r'^accounts/', include('allauth.urls')),

    # Your stuff: custom urls includes go here
    url(r'^weblog/', include('zinnia.urls')),
    url(r'^comments/', include('django_comments.urls')),


] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

When I run python manage.py migrate I get the following error:

"Model '%s.%s' not registered." % (app_label, model_name))
LookupError: Model 'users.User' not registered.

How can I fix this?

Flavio Barros
  • 996
  • 1
  • 11
  • 29
  • It says something about `users.User`. In which app is the code for that model? Is that app in your `INSTALLED_APS` ? – Ralf May 01 '18 at 18:03
  • 1
    This is the default configuration of cookiecutter-django. It works but doens't work with zinnia. The weird thing is that in zinnia docs there is no mention about change the users model conf. So I think that it should be working. – Flavio Barros May 01 '18 at 18:07

1 Answers1

0

I found that is a 'bug' on Zinnia by the way that loads User model.

In zinnia/models/author.py:

def safe_get_user_model():
    """
    Safe loading of the User model, customized or not.
    """
    user_app, user_model = settings.AUTH_USER_MODEL.split('.')
    return apps.get_registered_model(user_app, user_model)

I changed it as:

[...]
from django.contrib.auth import get_user_model
[...]

def safe_get_user_model():
    """
    Safe loading of the User model, customized or not.
    """
    # user_app, user_model = settings.AUTH_USER_MODEL.split('.')
    # return apps.get_registered_model(user_app, user_model)
    return get_user_model()

and runs perfectly.

I'm trying to test it in a clean installation. If it works, i'll make a pull request with it.

  • did you see that your pull request failed on github? I believe that is because of style stuff. Fix that and I will accept your answer. – Flavio Barros Apr 16 '19 at 01:24