0

When I try to make an abstractUser Model Class I get this error message after I put AUTH_USER_MODEL = 'blog.User in my settings.py I followed the Wagtail custom user model example The Link to the site.

I'm using Django 1.11.3 and wagtail 2.0, python 3.5.4

Sitename = mysite

Appname = Blog

Model = Models.py User class

Stack Trace

(wagtail-9p7xWA1-) 0-10:22-/mnt/c/dev/wagtail/mysite (master) $ ./manage.py runserver

Unhandled exception in thread started by .wrapper at 0x7fc502ce8840> Traceback (most recent call last): File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/utils/autoreload.py", line 227, in wrapper fn(*args, **kwargs) File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run autoreload.raise_last_exception() File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/utils/autoreload.py", line 250, in raise_last_exception six.reraise(*_exception) File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise raise value.with_traceback(tb) File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/utils/autoreload.py", line 227, in wrapper fn(*args, **kwargs) File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/init.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate app_config.import_models() File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models self.models_module = import_module(models_module_name) File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 986, in _gcd_import File "", line 969, in _find_and_load File "", line 958, in _find_and_load_unlocked File "", line 673, in _load_unlocked
File "", line 665, in exec_module File "", line 222, in _call_with_frames_removed File "/mnt/c/dev/wagtail/mysite/home/models.py", line 5, in from wagtail.admin.edit_handlers import FieldPanel File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/wagtail/admin/edit_handlers.py", line 23, in from .forms import ( # NOQA File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/wagtail/admin/forms.py", line 6, in from django.contrib.auth.forms import AuthenticationForm, PasswordResetForm File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/contrib/auth/forms.py", line 22, in UserModel = get_user_model() File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/contrib/auth/init.py", line 193, in get_user_model return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False) File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/apps/registry.py", line 203, in get_model app_config.import_models() File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models self.models_module = import_module(models_module_name) File "/home/Username/.local/share/virtualenvs/wagtail-9p7xWA1-/lib/python3.5/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/mnt/c/dev/wagtail/mysite/blog/models.py", line 17, in from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel, \

ImportError: cannot import name 'FieldPanel'

a bit of code if i do this

blog/Models.py

from django import forms
from django.db import models


from modelcluster.fields import ParentalKey, ParentalManyToManyField
from modelcluster.contrib.taggit import ClusterTaggableManager
from taggit.models import TaggedItemBase

from wagtail.core.models import Page, Orderable
from wagtail.snippets.models import register_snippet
from wagtail.core.fields import RichTextField, StreamField
from wagtail.core.blocks import StructBlock, TextBlock, StreamBlock, \
    EmailBlock, CharBlock, RichTextBlock
from wagtail.images.blocks import ImageChooserBlock
from wagtail.embeds.blocks import EmbedBlock
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel, \
    InlinePanel, StreamFieldPanel
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.search import index

richtext_features = [
    'h1', 'h2', 'h3', 'hr',
    'bold', 'italic', 'link',
    'ol', 'ul', 'embed', 'image',
]



class BlogIndexPage(Page):

    intro = RichTextField(blank=True)

    def get_context(self, request):

        # Update context to include only published posts, ordered by reverse-chron
        context = super().get_context(request)
        blogpages = self.get_children().live().order_by('-first_published_at')
        context['blogpages'] = blogpages
        return context


class BlogPageTag(TaggedItemBase):
    content_object = ParentalKey(
        'BlogPage',
        related_name='tagged_items',
        on_delete=models.CASCADE
    )


class BlogTagIndexPage(Page):

    def get_context(self, request):

        tag = request.GET.get('tag')
        blogpages = BlogPage.objects.filter(tags__name=tag)

        context = super().get_context(request)
        context['blogpages'] = blogpages
        return context


class BlogPage(Page):
    date = models.DateField("Post date")
    intro = models.CharField(max_length=250)
    body = RichTextField(blank=True)
    tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
    categories = ParentalManyToManyField('blog.BlogCategory', blank=True)
    feed_image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )

    def main_image(self):
        gallery_item = self.gallery_images.first()
        if gallery_item:
            return gallery_item.image
        else:
            return None

    search_fields = Page.search_fields + [
        index.SearchField('intro'),
        index.SearchField('body'),
        index.FilterField('date'),
    ]

    content_panels = Page.content_panels + [
        MultiFieldPanel([
            FieldPanel('date'),
            FieldPanel('tags'),
            FieldPanel('categories', widget=forms.CheckboxSelectMultiple),
        ], heading="Blog information"),
        FieldPanel('intro'),
        FieldPanel('body', classname="full"),
        InlinePanel('gallery_images', label="Gallery Images"),
    ]

    promote_panels = [
        MultiFieldPanel(Page.promote_panels, 'Common page Config'),
        ImageChooserPanel('feed_image'),
    ]


class BlogPageRelatedLink(Orderable):
    page = ParentalKey(BlogPage, related_name='related_links')
    name = models.CharField(max_length=255)
    url = models.URLField()

    panels = [
        FieldPanel('name'),
        FieldPanel('url'),
    ]


class BlogPageGalleryImage(Orderable):
    page = ParentalKey(
        BlogPage,
        on_delete=models.CASCADE,
        related_name='gallery_images'
    )

    image = models.ForeignKey(
        'wagtailimages.Image',
        on_delete=models.CASCADE,
        related_name='+'
    )

    caption = models.CharField(blank=True, max_length=250)

    panels = [
        ImageChooserPanel('image'),
        FieldPanel('caption')
    ]


class PersonBlock(StructBlock):
    name = CharBlock(icon="user")
    image = ImageChooserBlock(required=False, icon="image")
    email = EmailBlock(icon="mail")

    class Meta:
        template = 'blocks/person.html'


class TwoColumnBlock(StructBlock):

    left_column = PersonBlock(icon='arrow-right', label='Left column content')
    right_column = PersonBlock(icon='arrow-right', label='Right column content')

    class Meta:
        template = 'blocks/person.html'
        icon = 'user'
        label = 'Two Columns'


class StoryBlock(StreamBlock):
    title = TextBlock(classname="full title")
    text = RichTextBlock(features=richtext_features)

    class Meta:
        icon = 'bold'
        template = 'blocks/column.html'


class TwoStoryBlock(StructBlock):

    left_column = StoryBlock(icon='arrow-right', label='Left column content')
    right_column = StoryBlock(icon='arrow-right', label='Right column content')

    class Meta:
        template = 'blocks/two_column_block.html'
        icon = 'bold'


class BackgroundBlock(StructBlock):
    background = ImageChooserBlock(icon="image")
    streamblock = StreamBlock(
        [
            ('title', CharBlock(classname="full title")),
            ('person', PersonBlock()),
            ('twocolumnblock', TwoColumnBlock()),
            ('twostoryblock', TwoStoryBlock()),
            ('richtext', RichTextBlock(features=richtext_features)),
        ],
        required=False
    )

    class Meta:
        icon = 'cogs'
        template = 'blocks/background.html'


class BackgroundNoButtonBlock(StructBlock):
    background = ImageChooserBlock(icon="image")
    streamblock = StreamBlock(
        [
            ('title', CharBlock(classname="full title")),
            ('richtext', RichTextBlock(features=richtext_features)),
        ],
        required=False
    )

    class Meta:
        icon = 'cogs'
        template = 'blocks/background_no_button.html'


class TextAndImageBlock (StreamBlock):
    text = RichTextBlock(features=richtext_features)
    image = ImageChooserBlock()

    class Meta:
        icon = 'bold'
        template = 'blocks/column.html'


class TwoTextAndImageBlock(StructBlock):
    left_column = TextAndImageBlock(icon='arrow-right', label='Left column content')
    right_column = TextAndImageBlock(icon='arrow-right', label='Right column content')

    class Meta:
        template = 'blocks/two_column_block.html'
        icon = 'bold'


class LandingPage(Page):
    body = StreamField(
        [
            ('heading', CharBlock(classname="full title")),
            ('paragraph', RichTextBlock()),
            ('backgroundnobutton', BackgroundNoButtonBlock()),
            ('background', BackgroundBlock(max_num=10, block_counts={'video': {'max_num': 2}})),
            ('embedded_video', EmbedBlock(icon="media")),
            ('twostoryblock', TwoStoryBlock(icon="bold")),
            ('two_column_block', TwoColumnBlock(icon="view")),
            ('textandimage', TwoTextAndImageBlock()),
        ],
        null=True,
        blank=True
    )

    content_panels = Page.content_panels + [
        StreamFieldPanel('body'),
    ]


@register_snippet
class BlogCategory(models.Model):
    name = models.CharField(max_length=255)
    icon = models.ForeignKey(
        'wagtailimages.Image', null=True, blank=True,
        on_delete=models.SET_NULL, related_name='+'
    )

    panels = [
        FieldPanel('name'),
        ImageChooserPanel('icon'),
    ]

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = 'blog categories'

Settings/base.py

     import os

PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/


# Application definition

INSTALLED_APPS = [
    'home',
    'search',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
    'users',
    'wagtail.contrib.forms',
    'wagtail.contrib.redirects',
    'wagtail.embeds',
    'wagtail.sites',
    'wagtail.users',
    'wagtail.snippets',
    'wagtail.documents',
    'wagtail.images',
    'wagtail.search',
    'wagtail.admin',
    'wagtail.core',

    'modelcluster',
    'taggit',
]

MIDDLEWARE = [
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',

    'wagtail.core.middleware.SiteMiddleware',
    'wagtail.contrib.redirects.middleware.RedirectMiddleware',
]

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(PROJECT_DIR, 'templates'),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
WAGTAILGRIDDER_CLEAR_CACHE = False

# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
AUTH_USER_MODEL = 'users.User'
AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

STATICFILES_DIRS = [
    os.path.join(PROJECT_DIR, 'static'),
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'


# Wagtail settings

WAGTAIL_SITE_NAME = "mysite"

# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
BASE_URL = 'http://example.com'

*users/models.py *

from django.db import models
from django.contrib.auth.models import AbstractUser


class User(AbstractUser):
    pass
  • 2
    It looks like you've got a circular import. It's tricky to know what to suggest without seeing the rest of the code. You could try moving `User` into a separate app `users`. – Alasdair Apr 04 '18 at 09:17
  • Already tried that same error but it happens after i added the AUTH_USER_MODEL in base.py – TheRuff112 Apr 04 '18 at 09:23
  • Added the whole of base.py but for the the issue is with wagtail.admin.edit_handlers and the AUTH_USER_MODEL – TheRuff112 Apr 04 '18 at 09:28
  • My point is that you might be able to fix the problem by moving the `User` model to a different app `users` and changing the setting to `AUTH_USER_MODEL = 'users.User'` The settings doesn't show what the issue is. Please show the rest of the `models.py`. – Alasdair Apr 04 '18 at 09:35
  • I added the rest of the models.py (also new to django/wagtail) – TheRuff112 Apr 04 '18 at 09:39
  • You don't use `User` or `AUTH_USER_MODEL` anywhere else in that `models.py`, so I really think that moving it to a different app will fix the problem. If doing that gave you an error, at least it should have been a different error. – Alasdair Apr 04 '18 at 09:47
  • i did that i still get the issue i will update the question – TheRuff112 Apr 04 '18 at 09:54
  • One more question - is this a new project? It's extremely difficult to change `AUTH_USER_MODEL` for an existing project. Even for moving the user from `blog` to `users`, it's probably easiest to delete the migrations and start with a fresh database. – Alasdair Apr 04 '18 at 09:57
  • this project was from the wagtail beginners tutorial with some added thing from myself after i completed it i already tried to do it in a diffrent project but same result so its kinda newish – TheRuff112 Apr 04 '18 at 10:04
  • Your updated question doesn't show the error you are getting after moving the model to `users`. A 'newish' project doesn't help. If you have already created the initial migrations, then it's extremely difficult to change the `AUTH_USER_MODEL`. – Alasdair Apr 04 '18 at 10:10
  • Ok what i did was made a backup of my SQLlite database so when i made a migration i start with new fresh database so it AUTH_USER_MODEL = 'users.User' i think the issue was that already had a user from ./manage.py createsuperuser before adding the custom user class same with the new project i made but i thank you for the help – TheRuff112 Apr 04 '18 at 10:37
  • and god that bad english – TheRuff112 Apr 04 '18 at 10:37

0 Answers0