TreeModelAdmin for Wagtail
Project description
Wagtail-TreeModelAdmin
Wagtail-TreeModelAdmin is an extension for Wagtail's wagtail-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.8+
- Django 3.2 (LTS), 4.1 (current)
- Wagtail 5.1+
- wagtail-modeladmin
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_modeladmin
if it's not already) as an installed app in your Djangosettings.py
:
INSTALLED_APPS = (
...
'wagtail_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-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_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
File details
Details for the file wagtail_treemodeladmin-1.9.2.tar.gz
.
File metadata
- Download URL: wagtail_treemodeladmin-1.9.2.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e68a874844f54fbd774285a1d8b205c375efc0e9b72c3193aa7b6c527f09d852 |
|
MD5 | 37b2530bf10a8b9ac8caaa96c681d800 |
|
BLAKE2b-256 | edf30318280a5cb0dab879aad0c93ef17d0c957a613f49442a0e3b2ee163586b |
File details
Details for the file wagtail_treemodeladmin-1.9.2-py3-none-any.whl
.
File metadata
- Download URL: wagtail_treemodeladmin-1.9.2-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c05a9487a835788e8ba6c0fac29e76b1150f19547d6abb5e76e5542b5ad3079 |
|
MD5 | 8fb85ce8fc471a5974f29e6fb6bec91a |
|
BLAKE2b-256 | 4ffd4f0687ce4f5c078e85e80ef6aab1f42c6180f4e989a325875fbe236852f6 |