我在home / models.py中创建了一个类来创建页面,并根据与文档https://docs.djangoproject.com/en/2.1/ref/contrib/sites/相同的网站ID将其添加到wagtail cms管理界面中的特定网站 我也继承了类内的MenuPage以使用子菜单 但是当我进行迁移时,即使更改继承,也会出现页面继承错误。 请帮忙吗?
from django.db import models
from django.contrib.sites.models import Site
from django.contrib.sites.managers import CurrentSiteManager
from django.utils import translation
# New imports added for ParentalKey, Orderable, InlinePanel, ImageChooserPanel
from modelcluster.fields import ParentalKey
from wagtail.core.models import Page, PageManager, Orderable
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel, InlinePanel
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.search import index
from wagtailmenus.models import MenuPage
from wagtailmenus.panels import menupage_panel
class TranslatedField():
def __init__(self, en_field, sv_field):
self.en_field = en_field
self.sv_field = sv_field
def __get__(self, instance, owner):
if translation.get_language() == 'sv':
return getattr(instance, self.sv_field)
else:
return getattr(instance, self.en_field)
class HomePage(MenuPage):
body = RichTextField(blank=True)
site = models.ForeignKey(Site, on_delete=models.CASCADE)
objects = models.Manager()
on_site = CurrentSiteManager()
content_panels = MenuPage.content_panels + [
FieldPanel('body', classname="full"),
FieldPanel('site'),
]
class HomeOnePage(MenuPage):
body = RichTextField(blank=True)
site = models.ForeignKey(Site, on_delete=models.CASCADE)
objects = models.Manager()
on_site = CurrentSiteManager()
content_panels = MenuPage.content_panels + [
FieldPanel('body', classname="full"),
FieldPanel('site'),
]
class BlogIndexPage(MenuPage):
intro = RichTextField(blank=True)
site = models.ForeignKey(Site, on_delete=models.CASCADE)
objects = models.Manager()
on_site = CurrentSiteManager()
content_panels = MenuPage.content_panels + [
FieldPanel('intro', classname="full"),
FieldPanel('site'),
]
class BlogPage(MenuPage):
date = models.DateField("Post date")
intro = models.CharField(max_length=250)
body = RichTextField(blank=True)
site = models.ForeignKey(Site, on_delete=models.CASCADE)
objects = models.Manager()
on_site = CurrentSiteManager()
#translated_title = TranslatedField(
# 'title',
# 'title_sv',
#)
#body = TranslatedField(
# 'body_en',
# 'body_sv',
#)
search_fields = MenuPage.search_fields + [
index.SearchField('intro'),
index.SearchField('body'),
]
content_panels = MenuPage.content_panels + [
FieldPanel('date'),
FieldPanel('intro'),
FieldPanel('body', classname="full"),
FieldPanel('site'),
InlinePanel('gallery_images', label="Gallery images", help_text = "add photo to your site"),
]
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'),
]
SystemCheckError: System check identified some issues:
ERRORS:
home.BlogIndexPage: (wagtailcore.E002) Manager does not inherit from PageManager
HINT: Ensure that custom Page managers inherit from wagtail.core.models.PageManager
home.BlogPage: (wagtailcore.E002) Manager does not inherit from PageManager
HINT: Ensure that custom Page managers inherit from wagtail.core.models.PageManager
home.HomeOnePage: (wagtailcore.E002) Manager does not inherit from PageManager
HINT: Ensure that custom Page managers inherit from wagtail.core.models.PageManager
home.HomePage: (wagtailcore.E002) Manager does not inherit from PageManager
HINT: Ensure that custom Page managers inherit from wagtail.core.models.PageManager
WARNINGS:
home.BlogIndexPage.site: (wagtailcore.W001) Field hasn't specified on_delete action
HINT: Set on_delete=models.SET_NULL and make sure the field is nullable or set on_delete=models.PROTECT. Wagtail does not allow simple database CASCADE because it will corrupt its tree storage.
home.BlogPage.site: (wagtailcore.W001) Field hasn't specified on_delete action
HINT: Set on_delete=models.SET_NULL and make sure the field is nullable or set on_delete=models.PROTECT. Wagtail does not allow simple database CASCADE because it will corrupt its tree storage.
home.HomeOnePage.site: (wagtailcore.W001) Field hasn't specified on_delete action
HINT: Set on_delete=models.SET_NULL and make sure the field is nullable or set on_delete=models.PROTECT. Wagtail does not allow simple database CASCADE because it will corrupt its tree storage.
home.HomePage.site: (wagtailcore.W001) Field hasn't specified on_delete action
HINT: Set on_delete=models.SET_NULL and make sure the field is nullable or set on_delete=models.PROTECT. Wagtail does not allow simple database CASCADE because it will corrupt its tree storage.
答案 0 :(得分:0)
问题出在那一行:
objects = models.Manager()
Page
型must inherit from wagtail.core.models.PageManager
上的经理。但是,在这种情况下,经理无济于事,应只保留该行。