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

Uploaded Source

Built Distribution

wagtail_modelchooser-2.2.2-py2.py3-none-any.whl (12.0 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: wagtail-modelchooser-2.2.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/33.1.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.3

File hashes

Hashes for wagtail-modelchooser-2.2.2.tar.gz
Algorithm Hash digest
SHA256 504f632c82e9137650cbdf9059c80e6643f73f44e85c64f4566690972a36baa7
MD5 d902945ca40027e3c5856d83034342d6
BLAKE2b-256 3ceba0c9b995c51728e62441013c8150902099000111149b289775eb601ff8a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wagtail_modelchooser-2.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/33.1.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.3

File hashes

Hashes for wagtail_modelchooser-2.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4b965f41c723100ce48f84802f2baca742073b0b9d679bedc094ea99c0ba4557
MD5 73ce2ef00253de8f6c9526e977a7f9ed
BLAKE2b-256 d775d1302825c8151b74b7cbcab4d447f0a34f8abf834d66c08f41b68b32c6fd

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