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.10+
- Django 4.2 (LTS)+
- 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_modeladminif 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 DjangoForeignKeyon a child model.child_field: Therelated_nameon 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_registered 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wagtail_treemodeladmin-1.10.1.tar.gz.
File metadata
- Download URL: wagtail_treemodeladmin-1.10.1.tar.gz
- Upload date:
- Size: 182.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4d83463cf0cff23354c315c70e8c84b6021aa79cc762e5a403f1f2b3c25240c
|
|
| MD5 |
42857315769e21c78ba4647e3a848f0f
|
|
| BLAKE2b-256 |
2afe9f9f78038e36ffd1dbe192c5210fdb3bc381280b77ee781fc7fe4b98322c
|
Provenance
The following attestation bundles were made for wagtail_treemodeladmin-1.10.1.tar.gz:
Publisher:
release.yml on cfpb/wagtail-treemodeladmin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wagtail_treemodeladmin-1.10.1.tar.gz -
Subject digest:
f4d83463cf0cff23354c315c70e8c84b6021aa79cc762e5a403f1f2b3c25240c - Sigstore transparency entry: 732848058
- Sigstore integration time:
-
Permalink:
cfpb/wagtail-treemodeladmin@cf55cfbfae6e7f5592bc29dbbd55664d5c69430b -
Branch / Tag:
refs/tags/1.10.1 - Owner: https://github.com/cfpb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cf55cfbfae6e7f5592bc29dbbd55664d5c69430b -
Trigger Event:
release
-
Statement type:
File details
Details for the file wagtail_treemodeladmin-1.10.1-py3-none-any.whl.
File metadata
- Download URL: wagtail_treemodeladmin-1.10.1-py3-none-any.whl
- Upload date:
- Size: 21.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c05e7c5dca48f785d76061a82090d0bd27384d2be5343363069c95c9b3bc359d
|
|
| MD5 |
b3313bf274642de0ad3d338d5dd73964
|
|
| BLAKE2b-256 |
a581abc96db7d81602952555f5cc3f4e99226c2c4a463af5b1c79799d04d623f
|
Provenance
The following attestation bundles were made for wagtail_treemodeladmin-1.10.1-py3-none-any.whl:
Publisher:
release.yml on cfpb/wagtail-treemodeladmin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wagtail_treemodeladmin-1.10.1-py3-none-any.whl -
Subject digest:
c05e7c5dca48f785d76061a82090d0bd27384d2be5343363069c95c9b3bc359d - Sigstore transparency entry: 732848061
- Sigstore integration time:
-
Permalink:
cfpb/wagtail-treemodeladmin@cf55cfbfae6e7f5592bc29dbbd55664d5c69430b -
Branch / Tag:
refs/tags/1.10.1 - Owner: https://github.com/cfpb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cf55cfbfae6e7f5592bc29dbbd55664d5c69430b -
Trigger Event:
release
-
Statement type: