TreeModelAdmin for Wagtail
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.
- Getting help
- Getting involved
- Credits and references
- Python 3.6+
- Django 2.2 (LTS), 3.1 (current)
- Wagtail 2.11 (LTS), <3 (current)
It should be compatible with all intermediate versions, as well. If you find that it is not, please file an issue.
- Install wagtail-treemodeladmin:
pip install wagtail-treemodeladmin
wagtail.contrib.modeladminif it's not already) as an installed app in your Django
INSTALLED_APPS = ( ... 'wagtail.contrib.modeladmin', 'treemodeladmin', ... )
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
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
# 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.
Wagtail-TreeModelAdmin uses three new attributes on ModelAdmin subclasses to express parent/child relationships:
parent_field: The name of the Django
ForeignKeyon a child model.
related_nameon a Django
TreeModelAdmin subclass can specify both parent and child relationships. The root of the tree (either the
TreeModelAdmin included in a
ModelAdminGroup or the
TreeModelAdmin subclass) should only include
Please add issues to the issue tracker.
General instructions on how to contribute can be found in CONTRIBUTING.
Credits and references
- Forked from cfgov-refresh
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size wagtail_treemodeladmin-1.5.0-py2.py3-none-any.whl (20.1 kB)||File type Wheel||Python version py2.py3||Upload date||Hashes View|
|Filename, size wagtail-treemodeladmin-1.5.0.tar.gz (16.0 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for wagtail_treemodeladmin-1.5.0-py2.py3-none-any.whl
Hashes for wagtail-treemodeladmin-1.5.0.tar.gz