Skip to main content

Allows using StructBlock and ListBlock as model fields

Project description

wagtail-block-fields

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

Just like StreamField wraps StreamBlock, this package provides:

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

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())

In templates

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

<ul>
{% for tag in page.tags %}
    <li>{{ tag }}</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

License

MIT

Project details


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.2.2.tar.gz (46.6 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.2.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wagtail_block_fields-0.2.2.tar.gz
  • Upload date:
  • Size: 46.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wagtail_block_fields-0.2.2.tar.gz
Algorithm Hash digest
SHA256 385f38155299d5e45e7c5b011415df9a6ebdef716b9e43ae9dc48926216b8bad
MD5 78396f48671dfd3c34d2023c452af290
BLAKE2b-256 a9870d1210601a1b0af328e0066f493c242280cabe0af39427e6d24c29574ca5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for wagtail_block_fields-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4f134a5c13f041ab17d354f8ac9100c0a6cf830770d0b6cb8f1a2e6f5da967a0
MD5 2d1093bcf3baa656798638b0ba0f3f0a
BLAKE2b-256 bdee2bca4d0d831d9caed71dccc38d1c971e6e784e2e87bfb29827822eacae36

See more details on using hashes here.

Provenance

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page