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 wagtailmodelchooser

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

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-0.2.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

wagtail_modelchooser-0.2.0-py2.py3-none-any.whl (12.3 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for wagtail-modelchooser-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b0d292c40d2858d9704b8bb3ffce28a41464f2dfb0b8513f5297b9cd0b76d6df
MD5 484ca1ffd778dc41c87c0c6edcc3a8e6
BLAKE2b-256 01750c83aa5161e4365ae43edcc71e8f1dd0fad4a89778e16e021503c33fc569

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wagtail_modelchooser-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d1555cc677844d7b00c083df87d7c2a0e95438d22a1240f56d7e2ead31851a00
MD5 d5ecf8055fe80fbf305ed96cdafc9eed
BLAKE2b-256 7124a3a9607a1d6daa2bb0c12865b282433e65f58a31cbd6f3bbd09e595484e9

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