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 2.7+, 3.6+
- Django 1.11+, 2.0+
- Wagtail 1.13+, 2.0+
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.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | dea51af63206e42276d96653cb979df6117f06eaae0786afc283384ad8f8bb92 |
|
MD5 | ff63536836d2913ea03a1bc453b5b2a3 |
|
BLAKE2b-256 | 275834ba9e7c869b1eff2f12f56b91ca846fdfdc98a0b7152889242cd99f1fa3 |
Hashes for wagtail_treemodeladmin-1.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91ca8f42630636a531a705fc5d4822965d6e79ae4ba5c3c6b321549a0acaadb2 |
|
MD5 | 71c58703f701096815ac8ec3e0422875 |
|
BLAKE2b-256 | 40aa3566255d0da20c53fa7cafe8945642c9d8eab016d9579c41baaa1f2db71f |
Hashes for wagtail_treemodeladmin-1.0.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d24577bf36930d5eb92c9df4459c677b9a9cb3154210c205709368b74cbd6a9 |
|
MD5 | f753669a2958230644a88313429e256a |
|
BLAKE2b-256 | e3708e22667d65b5a3941d37f500a36277e62131eea71c5a7e0fb5dd61bc6fcc |