Wagtail;: ValueError: too many values to unpack (expected 2) when creating a large custom StructBlock for StreamField

Wagtail;: ValueError: too many values to unpack (expected 2) when creating a large custom StructBlock for StreamField

我正在为 StreamField 创建一个 StructBlock。目标是创建一个块来上传图像以及大量元数据。元数据是 CharBlocks、ImageChooserBlocks 和 RichTextBlocks 的混合体。

当我想使用 makemigrations 在数据库中进行更改时,我收到错误消息 "ValueError: too many values to unpack (expected 2)"

前面我得到:

File "C:...\models.py", line 66, in CatalogueIndexPage
    'image', TurnerImageBlock(),
  File "C:...\wagtail\lib\site-packages\wagtail\wagtailcore\fields.py", line 51, in __init__
    self.stream_block = StreamBlock(block_types, required=not self.blank)
  File "C:...\wagtail\lib\site-packages\wagtail\wagtailcore\blocks\stream_block.py", line 47, in __init__
    for name, block in local_blocks:

我在想可能是字段太多了。但这应该不是问题。我也看过格式,但看不到任何格式。我在下面包含了 models.py 代码。

from datetime import date

from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.fields import StreamField
from wagtail.wagtailcore import blocks
from wagtail.wagtailadmin.edit_handlers import StreamFieldPanel
from wagtail.wagtailimages.blocks import ImageChooserBlock


class TurnerImageBlock(blocks.StructBlock):
    image_title = blocks.CharBlock(required=True)
    thumbnail = ImageChooserBlock()
    full_image = ImageChooserBlock()
    copyright_conditions_of_use = blocks.CharBlock()

    unique_identifying_number = blocks.CharBlock()
    date_of_submission = blocks.DateTimeBlock(default=date.today)

    # person submitting
    person_submitting_images = blocks.CharBlock()
    current_owning_inst_person = blocks.CharBlock()
    inst_personal_unique_impression_accession_no = blocks.CharBlock()
    inst_personal_unique_image_accession_no = blocks.CharBlock()

    # Dimensions
    impression_physical_dimensions = blocks.CharBlock()
    size_of_paper = blocks.CharBlock()
    size_of_plate_impression = blocks.CharBlock()
    size_of_picture = blocks.CharBlock()

    # Physical Attributes
    paper_type = blocks.CharBlock()
    comments_on_impression = blocks.RichTextBlock()
    condition = blocks.CharBlock()
    physical_history = blocks.CharBlock()

    # Digital Image
    digital_image_dimensions = blocks.CharBlock()
    digital_image_capture_mechanism = blocks.CharBlock()
    imaging_device = blocks.CharBlock()
    device_settings = blocks.CharBlock()
    calibration = blocks.CharBlock()
    date_of_capture = blocks.CharBlock()

    # Engraving info
    rawlinson_finerg_number = blocks.CharBlock()
    proposed_version_state = blocks.CharBlock()
    engraver = blocks.CharBlock()
    original_engraving_date = blocks.CharBlock()
    original_publication = blocks.CharBlock()
    actual_publication = blocks.CharBlock()

    # text and info on impression
    printed_text_on_impression = blocks.RichTextBlock()
    written_info_on_impression = blocks.RichTextBlock()
    turner_touching_comments = blocks.RichTextBlock()
    previous_collection_owner = blocks.RichTextBlock()

    links_related_info = blocks.CharBlock()
    histories_or_original_drawing = blocks.CharBlock()


class CatalogueIndexPage(Page):

    body = StreamField([
        'image', TurnerImageBlock(),
    ])

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

我见过类似的问题,说是 dictionary/tuple 等错误。但我经验不足,看不出问题出在我的代码中。

StreamField 采用元组列表,因此

body = StreamField([
    'image', TurnerImageBlock(),
])

应该变成:

body = StreamField([
    ('image', TurnerImageBlock()),
])