简体   繁体   English

g“没有字段名称”

[英]Wagtail “has no field name”

I'm fairly new to wagtail so please excuse any glaring mistakes. 我是新来的w,所以请原谅任何明显的错误。 I'm attempting to create a new page type called PortfolioItemPage. 我正在尝试创建一个名为PortfolioItemPage的新页面类型。 I am getting the following error when trying to use runserver, makemigrations or migrate: 尝试使用运行服务器,makemigrations或迁移时出现以下错误:

Unhandled exception in thread started by <function check_errors.

<locals>.wrapper at 0x10900f048>
Traceback (most recent call last):
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/django/db/models/options.py", line 566, in get_field
    return self.fields_map[field_name]
KeyError: 'project_title'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
    self.check(display_num_errors=True)
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/django/core/management/base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/django/core/management/base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/django/core/checks/registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/admin/checks.py", line 62, in get_form_class_check
    edit_handler = cls.get_edit_handler()
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/utils/decorators.py", line 53, in __call__
    return self.value
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/utils/decorators.py", line 49, in value
    return self.fn(self.cls)
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py", line 768, in get_edit_handler
    return edit_handler.bind_to_model(cls)
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py", line 131, in bind_to_model
    new.on_model_bound()
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py", line 276, in on_model_bound
    for child in self.children]
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py", line 276, in <listcomp>
    for child in self.children]
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py", line 131, in bind_to_model
    new.on_model_bound()
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py", line 276, in on_model_bound
    for child in self.children]
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py", line 276, in <listcomp>
    for child in self.children]
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py", line 131, in bind_to_model
    new.on_model_bound()
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/wagtail/admin/edit_handlers.py", line 480, in on_model_bound
    self.db_field = self.model._meta.get_field(self.field_name)
  File "/Users/jlspencergarlitz/.venvs/jls-jmSlWnDA/lib/python3.6/site-packages/django/db/models/options.py", line 568, in get_field
    raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: PortfolioItemPage has no field named 'project_title'

models.py models.py

class PortfolioPageTag(TaggedItemBase):
        content_object = ParentalKey('PortfolioItemPage',
                                     related_name='tagged_items')


class PortfolioItemPage(Page):
    project_title = blocks.CharBlock()
    project_details_summary = blocks.CharBlock()
    description = blocks.RichTextBlock()
    date = blocks.DateBlock()
    client = blocks.CharBlock()
    tags = ClusterTaggableManager(through=PortfolioPageTag, blank=True)
    location = blocks.CharBlock()
    client_photo = ImageChooserBlock(required=False)
    client_title = CommonHeadingBlock(required=False)
    client_testimonial = blocks.RichTextBlock(required=False)
    images = blocks.ListBlock(ImageChooserBlock())

    content_panels = Page.content_panels + [
        FieldPanel('project_title'),
        MultiFieldPanel([
            FieldPanel('project_details_summary'),
            FieldPanel('description'),
            FieldPanel('date')],
            heading="Project Basics",
            classname="collapsible collapsed"
        ),
        MultiFieldPanel([
            FieldPanel('client'),
            FieldPanel('tags'),
            FieldPanel('location')],
            heading="Meta Information",
            classname="collapsible collapsed"
        ),
        MultiFieldPanel([
            ImageChooserPanel('client_photo'),
            FieldPanel('client_title'),
            FieldPanel('client_testimonial')],
            heading="Client Testimonial",
            classname="collapsible collapsed"
        ),
        FieldPanel('images',)
    ]

    promote_panels = Page.promote_panels + [
        FieldPanel('tags'),
    ]

I've made sure the spelling is correct and done quite a few google searches but I cannot seem to figure the issue out. 我已经确保拼写正确,并进行了很多Google搜索,但我似乎无法弄清楚问题所在。 I can tell the field is there in the model. 我可以知道模型中存在该字段。 When removing the content_panels I am able to properly migrate the models into the db, but as soon as I add the content_panel back it fails. 当删除content_panels我可以将模型正确迁移到数据库中,但是一旦我将content_panel添加回数据库,它就会失败。 Am I not using the FieldPanel or MultiFieldPanel correctly? 我没有正确使用FieldPanel或MultiFieldPanel吗? I am using Wagtail2 and Django2 with Python3. 我将Wagtail2和Django2与Python3结合使用。

Block objects such as blocks.CharBlock() are only valid within StreamField definitions. 诸如blocks.CharBlock()类的块对象仅在StreamField定义内有效。 You need to use Django model fields instead, such as models.CharField() or Wagtail's RichTextField . 您需要改用Django模型字段 ,例如models.CharField()或Wagtail的RichTextField

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM