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.0, 2.2
- Wagtail 1.13, 2.3, 2.8
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 Distributions
Hashes for wagtail-treemodeladmin-1.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 447e4e590f002ae42766f001bcbfda3c8b2815b3a9920648c72fb2e9aee3025f |
|
MD5 | 22468885768f5b8b86108d2820bf41a5 |
|
BLAKE2b-256 | f216bee86386388b9e57e009936cbbe28f1a883bb75f88d9811d9423a805ea14 |
Hashes for wagtail_treemodeladmin-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5166462061ff05be2c0997defb41ac9b4767755042f1f2e914bc4913d3030cb6 |
|
MD5 | cdadc74ee748e1bf7589a9448a47cee6 |
|
BLAKE2b-256 | 3079203105c019fcf352a2d95bdbcad9a4f7b0abadff74939ce198430a88ef5d |
Hashes for wagtail_treemodeladmin-1.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7aa3487627f325405d698d661fbbb5543bccae0600440c2de5cc8690c9813282 |
|
MD5 | ee0f1bc093d64f3e19a6ad38d3e61d02 |
|
BLAKE2b-256 | 3fa6826aaee57871138a749d81b29883adc39fbe12f6ba0cb0e83c93addf2ab3 |