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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file wagtail-modelchooser-2.2.0.tar.gz
.
File metadata
- Download URL: wagtail-modelchooser-2.2.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cff5482b683c1db5468b6ae38d8e0f407a1fb1c87a394dd5319a1ffe28c180c |
|
MD5 | 45d3cc75185c1b50e0977a6b7cc78b38 |
|
BLAKE2b-256 | 2b1ab5f904b98c49b9b3fe5d294dc7e3f922d65c87912741646eb5b28a306132 |
File details
Details for the file wagtail_modelchooser-2.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: wagtail_modelchooser-2.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f940da7b4ba04d02041997d567ac12c45c2fb17c9101fcea40473d7d257004c |
|
MD5 | b086e39729aa9ce61bac4ddc3de81f61 |
|
BLAKE2b-256 | 2c75a3315231fc05e9c5f1cd2ca88ac4a1507357a216a607cb31dd1ce2eb60a3 |