Skip to main content

Model choosers for Wagtail admin

Project description

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 2.2 and upwards. For older versions of Wagtail check previous versions of the package.

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

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-modelchooser-2.2.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

wagtail_modelchooser-2.2.1-py2.py3-none-any.whl (11.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file wagtail-modelchooser-2.2.1.tar.gz.

File metadata

File hashes

Hashes for wagtail-modelchooser-2.2.1.tar.gz
Algorithm Hash digest
SHA256 e40257b4625646fb68213c219efe924c591e896b5597650d03aa7cfbbfc7b49a
MD5 e7c5100f12d09fab559304378eee236f
BLAKE2b-256 5d329f06e5da58d417f0f709953134ae60fed59f962dce94b77a85305daf15ae

See more details on using hashes here.

File details

Details for the file wagtail_modelchooser-2.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_modelchooser-2.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3e66d477a4f19bf5e53edbe6ee43a40ca17c9419a15a76b58e399595413b3f0f
MD5 950543a4a76ae9a80b23a12c34274bd8
BLAKE2b-256 c3ccd23355c4f031784ae967883a88415bbb4885c15176164822a7d80a200a55

See more details on using hashes here.

Supported by

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