TreeModelAdmin for Wagtail
Project description
Wagtail-TreeModelAdmin
Wagtail-TreeModelAdmin is an extension for Wagtail's ModelAdmin that allows for a page explorer-like navigation of Django model relationships within the Wagtail admin.
- Dependencies
- Installation
- Concepts
- Usage
- API
- Getting help
- Getting involved
- Licensing
- Credits and references
Dependencies
- Python 3.6, 3.8
- Django 1.11, 2.2
- Wagtail 2.3, 2.9, 2.10
It should be compatible with all intermediate versions, as well. If you find that it is not, please file an issue.
Installation
- Install wagtail-treemodeladmin:
pip install wagtail-treemodeladmin
- Add
treemodeladmin
(andwagtail.contrib.modeladmin
if it's not already) as an installed app in your Djangosettings.py
:
INSTALLED_APPS = (
...
'wagtail.contrib.modeladmin',
'treemodeladmin',
...
)
Concepts
Wagtail-TreeModelAdmin allows for a Wagtail page explorer-like navigation of Django one-to-many relationships within the Wagtail admin. In doing this, it conceptualizes the Django ForeignKey
relationship as one of parents-to-children. The parent is the destination to
of the ForeignKey
relationship, the child is the source of the relationship.
Wagtail-TreeModelAdmin is an extension of Wagtail's ModelAdmin. It is intended to be used exactly like ModelAdmin
.
Usage
Quickstart
To use Wagtail-TreeModelAdmin you first need to define some models that will be exposed in the Wagtail Admin.
# libraryapp/models.py
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=255)
class Book(models.Model):
author = models.ForeignKey(Author, on_delete=models.PROTECT)
title = models.CharField(max_length=255)
Then create the TreeModelAdmin
subclasses and register the root the tree using modeladmin_register
:
# libraryapp/wagtail_hooks.py
from wagtail.contrib.modeladmin.options import modeladmin_register
from treemodeladmin.options import TreeModelAdmin
from libraryapp.models import Author, Book
class BookModelAdmin(TreeModelAdmin):
model = Book
parent_field = 'author'
@modeladmin_register
class AuthorModelAdmin(TreeModelAdmin):
menu_label = 'Library'
menu_icon = 'list-ul'
model = Author
child_field = 'book_set'
child_model_admin = BookModelAdmin
Then visit the Wagtail admin. Library
will be in the menu, and will give you a list of authors, and each author will have a link that will take you to their books.
API
Wagtail-TreeModelAdmin uses three new attributes on ModelAdmin subclasses to express parent/child relationships:
parent_field
: The name of the DjangoForeignKey
on a child model.child_field
: Therelated_name
on a DjangoForeignKey
.child_model_admin
Any TreeModelAdmin
subclass can specify both parent and child relationships. The root of the tree (either the TreeModelAdmin
included in a ModelAdminGroup
or the @modeladmin_register
ed TreeModelAdmin
subclass) should only include child_*
fields.
Getting help
Please add issues to the issue tracker.
Getting involved
General instructions on how to contribute can be found in CONTRIBUTING.
Licensing
Credits and references
- Forked from cfgov-refresh
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
Hashes for wagtail-treemodeladmin-1.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5eee322a2a8e65fe4dfdd3ce83172a6ff66277b2c61fbd09616b19b89a00829 |
|
MD5 | b9997c601649d330f4a78c919f44e79d |
|
BLAKE2b-256 | bff9b28d4f844b6e8a01628548350f0b10912c572b1a2ef8bec9205331a7707b |
Hashes for wagtail_treemodeladmin-1.2.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a286908c9b39ef2b79a7688b898e806c782635ea3d9a20ece84476dab031d5cb |
|
MD5 | 4d01cb6a7b7df906d74fbc5b7579943a |
|
BLAKE2b-256 | 9894311f5e8b22597afa0a112b8e3692716807903777dd06435e08e7ddb4f6eb |