pythondjangocontent-management-systemwagtailwagtail-streamfield

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


I'm creating a StructBlock for StreamField. The goal is to create a block that will upload an image as well as a lot of metadata. The metadata is a mixture of CharBlocks, ImageChooserBlocks and RichTextBlocks.

When I want to make the changes in database using makemigrations I receive the error "ValueError: too many values to unpack (expected 2)"

Preceeding that I get:

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:

I was thinking that it may be due to too many fields. But that shouldn't be a problem. I have also looked at formatting but can't see any. I've included the models.py code below.

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'),
    ]

I have seen similar problems saying it's a dictionary/tuple etc error. But I'm not experienced enough to see where the problem is in my code.


Solution

  • StreamField takes a list of tuples, so

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

    should become:

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