Reputation: 250
I'm fairly new to wagtail so please excuse any glaring mistakes. I'm attempting to create a new page type called PortfolioItemPage. I am getting the following error when trying to use runserver, makemigrations or migrate:
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
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. 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. Am I not using the FieldPanel or MultiFieldPanel correctly? I am using Wagtail2 and Django2 with Python3.
Upvotes: 0
Views: 402
Reputation: 25237
Block objects such as blocks.CharBlock()
are only valid within StreamField
definitions. You need to use Django model fields instead, such as models.CharField()
or Wagtail's RichTextField
.
Upvotes: 1