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.3.1.tar.gz (47.7 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.3.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wagtail_block_fields-0.3.1.tar.gz
  • Upload date:
  • Size: 47.7 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.3.1.tar.gz
Algorithm Hash digest
SHA256 445c205e77d84f81800a2e54ada487b69aadb2f4144e08bcc559b36db00dbada
MD5 e95cbe61c8a42bf387127fce20c66f1e
BLAKE2b-256 55c19e83d10105daff619dbfab8e33a5778dc2771f92d08b03a95b8f4a6e7e2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_block_fields-0.3.1.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.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_block_fields-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f83622e0de686545a031b7757021497b309d018e363b29bcd02b397cd770bb4e
MD5 4c6b1993379aee4644ced8cdd2da78cf
BLAKE2b-256 fd7193e372dc50119c48266e6b87f9a16739e1fc76969939c84cec3e231f118e

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_block_fields-0.3.1-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

0.4.0

2 files

This release

0.3.1 This release

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