Skip to main content

wagtail-block-fields

Use Wagtail's StructBlock, ListBlock, and MultipleChoiceBlock as standalone model fields.

Just like StreamField wraps StreamBlock, this package provides:

  • StructField - wraps a StructBlock
  • ListField - wraps a ListBlock
  • MultipleChoiceField - wraps a MultipleChoiceBlock

Installation

pip install wagtail-block-fields

Usage

StructField

from wagtail.blocks import CharBlock, StructBlock
from wagtail_block_fields import StructField

class AddressBlock(StructBlock):
    street = CharBlock()
    city = CharBlock()
    postal_code = CharBlock()

class MyPage(Page):
    address = StructField(AddressBlock())
    
    contact = StructField([
        ('email', CharBlock()),
        ('phone', CharBlock()),
    ])

ListField

from wagtail.blocks import CharBlock
from wagtail_block_fields import ListField

class MyPage(Page):
    tags = ListField(CharBlock())
    categories = ListField(CharBlock(), min_num=1, max_num=5)
    addresses = ListField(AddressBlock())

MultipleChoiceField

from wagtail_block_fields import MultipleChoiceField

COLOR_CHOICES = [
    ("red", "Red"),
    ("green", "Green"),
    ("blue", "Blue"),
]

class MyPage(Page):
    colors = MultipleChoiceField(choices=COLOR_CHOICES)

In templates

<p>{{ page.address.street }}, {{ page.address.city }}</p>

<ul>
{% for tag in page.tags %}
    <li>{{ tag }}</li>
{% endfor %}
</ul>

<ul>
{% for color in page.colors %}
    <li>{{ color }}</li>
{% endfor %}
</ul>

{% for address in page.addresses %}
    <p>{{ address.street }}, {{ address.city }}</p>
{% endfor %}

Why?

Sometimes you need structured JSON data in a single field without the complexity of StreamField. These fields:

  • Store data as JSON in a single database column
  • Provide full Wagtail admin editing UI
  • Support validation, search indexing, and reference extraction
  • Work with migrations just like StreamField
  • Support nesting (e.g., MultipleChoiceField inside a StructField)

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtail_block_fields-0.4.0.tar.gz (48.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wagtail_block_fields-0.4.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file wagtail_block_fields-0.4.0.tar.gz.

File metadata

  • Download URL: wagtail_block_fields-0.4.0.tar.gz
  • Upload date:
  • Size: 48.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for wagtail_block_fields-0.4.0.tar.gz
Algorithm Hash digest
SHA256 f0bf2c4770a5340853a5aeda7878bddd77a7c3c4e4bbc085ebdd00ea1bdb3b9e
MD5 80e9e5cec2dff0c0fd5b16d80484923e
BLAKE2b-256 74ebd9a223272e0255a35667f651eb794fee1b3148b13708b972551351bd8fad

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_block_fields-0.4.0.tar.gz:

Publisher: publish.yml on joeyjurjens/wagtail-block-fields

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wagtail_block_fields-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_block_fields-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fe1c6d754cee8fbf7b16f5903d1e4bb751d3e9e614ebe3744e0be131b0b000e
MD5 25ddcd6827ca01c5e4d85eafd3c8e629
BLAKE2b-256 4d44a9b36d2002a81838b77c2d97fa282345137e50e1feef7301404acd040b77

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_block_fields-0.4.0-py3-none-any.whl:

Publisher: publish.yml on joeyjurjens/wagtail-block-fields

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page