Skip to main content

Wagtail model chooser

A plugin for Wagtail that provides a ModelChooserPanel and ModelChooserBlock for arbitrary models.

Installing

Install using pip:

pip install wagtail-modelchooser

Then add it to your INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    'wagtailmodelchooser',
    # ...
]

It works with Wagtail 1.4 and upwards.

Quick start

To enable the chooser for your model, you must register the model. For simple cases, decorate your model with @register_model_chooser:

from django.db import models

from wagtailmodelchooser import register_model_chooser


@register_model_chooser
class Author(models.Model):
    name = models.CharField(max_length=255)

    def __str__(self):
        # The ``str()`` of your model will be used in the chooser
        return self.name

You can then use either ModelChooserPanel in an edit handler definition, or ModelChooserBlock in a StreamField definition:

from wagtail.wagtailcore.blocks import RichTextBlock
from wagtail.wagtailcore.fields import StreamField
from wagtail.wagtailcore.models import Page
from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtailmodelchooser.blocks import ModelChooserBlock
from wagtailmodelchooser.edit_handlers import ModelChooserPanel

class Book(Page):
    name = models.CharField(max_length=255)
    author = models.ForeignKey(Author)

    content_panels = [
        FieldPanel('name'),
        ModelChooserPanel('author'),
    ]

class ContentPage(Page):
    body = StreamField([
        ('text', RichTextBlock()),
        ('author', ModelChooserBlock('books.Author')),
    ])

    content_panels = [
        StreamFieldPanel('body'),
    ]

Metadata

Release files for wagtail-modelchooser-1.13.1 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wagtail-modelchooser-1.13.1 2.0.0
File Size Uploaded
wagtail-modelchooser-1.13.1-2.0.0.tar.gz 8.4 kB Details

Release files / wagtail-modelchooser-1.13.1-2.0.0.tar.gz

Download URL wagtail-modelchooser-1.13.1-2.0.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
819cbcc59435f637a2f29a28e1faabd91e48cdcfde795ebbef26eab6718fb730
BLAKE2b-256 checksum
How to use checksums
f4371622c25fb8c2952033563d4f52e20e305ea20b1b1ba618da5a2a288af8ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

2.0.0 This release

1 release file

1.0.0

1 release file

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