AttributeError: 'DeferredAttribute' object has no attribute 'rel'
AttributeError: 'DeferredAttribute' object has no attribute 'rel'
我是 Wagtail 和 Django 的新手,我正在尝试构建一个模型,该模型将从 REST API 中提取数据并将其放入可以在模板上迭代的对象中。但是,在尝试迁移时,出现此错误:
related = getattr(model, self.relation_name).rel
AttributeError: 'DeferredAttribute' object has no attribute 'rel'
根据我目前收集到的信息,它与 OFSLOrgWebPage
页面模型中的 description
和 image
字段有关。以下是相关型号:
from __future__ import absolute_import, unicode_literals
from django.db import models
from django.shortcuts import render
from django.conf import settings
from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailcore.fields import RichTextField, StreamField
from wagtail.wagtailadmin.edit_handlers import FieldPanel, FieldRowPanel, MultiFieldPanel, \
InlinePanel, StreamFieldPanel
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtail.wagtailsearch import index
from wagtail.wagtailcore.blocks import StructBlock, StreamBlock, CharBlock, RichTextBlock, RawHTMLBlock, BooleanBlock
from wagtail.wagtailimages.blocks import ImageChooserBlock
from wagtail.wagtaildocs.blocks import DocumentChooserBlock
from modelcluster.fields import ParentalKey
import datetime
import json
import requests
class OFSLOrgWebPage(Page):
description = RichTextField(blank=True)
image = models.ForeignKey(
'serenity.Images',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
help_text="Council image that appears at the top of the page. Size: 500px x 400px"
)
def get_context(self, request):
context = super(OFSLOrgWebPage, self).get_context(request)
context['greek_orgs'] = self.greek_bios.objects.child_of(self).live()
return context
search_fields = Page.search_fields + [
index.SearchField('description'),
index.SearchField('greek_orgs'),
]
content_panels = Page.content_panels + [
InlinePanel('description', label='Council Description'),
InlinePanel('image', label='Council Image'),
InlinePanel('greek_bios'),
]
template = '../templates/ofsl_site/ofsl_org_web_page.html'
class Meta:
verbose_name = "OFSL Greek Org Page"
class OFSLGreekBio(Orderable):
name = models.CharField(max_length=255, blank=True)
letters = models.CharField(blank=True, max_length=3)
group_id = models.CharField(max_length=255, blank=True)
page = ParentalKey(OFSLOrgWebPage, related_name='greek_bios')
def get_groups(self):
response = requests.get(
('{}/api/v1/groups-search/?legacy_group_id={}?format=json').format(
settings['API_BASE_URL'],
int(self.group_id)))
if response.status_code != 200:
return ''
return response.json()['objects']
panels = [
FieldPanel('name'),
FieldPanel('letters'),
FieldPanel('group_id'),
]
class Meta:
verbose_name = "Greek Organization"
verbose_name_plural = "Greek Organizations"
编辑:我是 运行 Django 1.11.4 和 Wagtail 1.13.1
您正在使用 Django 2.0 和不支持它的 Wagtail 版本 - 第一个支持 Django 2.0 的 Wagtail 版本将是 Wagtail 2.0,目前处于测试阶段。
您需要降级到 Django 1。11.x,或 install the Wagtail 2.0 beta release。
您的 content_panels
定义为 description
和 image
使用了错误的面板类型 - InlinePanel
仅用于子对象关系,例如您的 greek_bios
.你可能想要这个:
content_panels = Page.content_panels + [
FieldPanel('description'),
ImageChooserPanel('image'),
InlinePanel('greek_bios'),
]
我是 Wagtail 和 Django 的新手,我正在尝试构建一个模型,该模型将从 REST API 中提取数据并将其放入可以在模板上迭代的对象中。但是,在尝试迁移时,出现此错误:
related = getattr(model, self.relation_name).rel
AttributeError: 'DeferredAttribute' object has no attribute 'rel'
根据我目前收集到的信息,它与 OFSLOrgWebPage
页面模型中的 description
和 image
字段有关。以下是相关型号:
from __future__ import absolute_import, unicode_literals
from django.db import models
from django.shortcuts import render
from django.conf import settings
from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailcore.fields import RichTextField, StreamField
from wagtail.wagtailadmin.edit_handlers import FieldPanel, FieldRowPanel, MultiFieldPanel, \
InlinePanel, StreamFieldPanel
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtail.wagtailsearch import index
from wagtail.wagtailcore.blocks import StructBlock, StreamBlock, CharBlock, RichTextBlock, RawHTMLBlock, BooleanBlock
from wagtail.wagtailimages.blocks import ImageChooserBlock
from wagtail.wagtaildocs.blocks import DocumentChooserBlock
from modelcluster.fields import ParentalKey
import datetime
import json
import requests
class OFSLOrgWebPage(Page):
description = RichTextField(blank=True)
image = models.ForeignKey(
'serenity.Images',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
help_text="Council image that appears at the top of the page. Size: 500px x 400px"
)
def get_context(self, request):
context = super(OFSLOrgWebPage, self).get_context(request)
context['greek_orgs'] = self.greek_bios.objects.child_of(self).live()
return context
search_fields = Page.search_fields + [
index.SearchField('description'),
index.SearchField('greek_orgs'),
]
content_panels = Page.content_panels + [
InlinePanel('description', label='Council Description'),
InlinePanel('image', label='Council Image'),
InlinePanel('greek_bios'),
]
template = '../templates/ofsl_site/ofsl_org_web_page.html'
class Meta:
verbose_name = "OFSL Greek Org Page"
class OFSLGreekBio(Orderable):
name = models.CharField(max_length=255, blank=True)
letters = models.CharField(blank=True, max_length=3)
group_id = models.CharField(max_length=255, blank=True)
page = ParentalKey(OFSLOrgWebPage, related_name='greek_bios')
def get_groups(self):
response = requests.get(
('{}/api/v1/groups-search/?legacy_group_id={}?format=json').format(
settings['API_BASE_URL'],
int(self.group_id)))
if response.status_code != 200:
return ''
return response.json()['objects']
panels = [
FieldPanel('name'),
FieldPanel('letters'),
FieldPanel('group_id'),
]
class Meta:
verbose_name = "Greek Organization"
verbose_name_plural = "Greek Organizations"
编辑:我是 运行 Django 1.11.4 和 Wagtail 1.13.1
您正在使用 Django 2.0 和不支持它的 Wagtail 版本 - 第一个支持 Django 2.0 的 Wagtail 版本将是 Wagtail 2.0,目前处于测试阶段。
您需要降级到 Django 1。11.x,或 install the Wagtail 2.0 beta release。
您的 content_panels
定义为 description
和 image
使用了错误的面板类型 - InlinePanel
仅用于子对象关系,例如您的 greek_bios
.你可能想要这个:
content_panels = Page.content_panels + [
FieldPanel('description'),
ImageChooserPanel('image'),
InlinePanel('greek_bios'),
]