Skip to main content

TreeModelAdmin for Wagtail

Project description

Wagtail-TreeModelAdmin

Build Status Coverage Status

TreeModelAdmin illustration with the books and authors example below

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

  • Python 3.6+
  • Django 2.2 (LTS), 3.1 (current)
  • Wagtail 2.7 (LTS), <3 (current)

It should be compatible with all intermediate versions, as well. If you find that it is not, please file an issue.

Installation

  1. Install wagtail-treemodeladmin:
pip install wagtail-treemodeladmin
  1. Add treemodeladmin (and wagtail.contrib.modeladmin if it's not already) as an installed app in your Django settings.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 Django ForeignKey on a child model.
  • child_field: The related_name on a Django ForeignKey.
  • 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

  1. TERMS
  2. LICENSE
  3. CFPB Source Code Policy

Credits and references

  1. Forked from cfgov-refresh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtail-treemodeladmin-1.4.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

wagtail_treemodeladmin-1.4.0-py2.py3-none-any.whl (20.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file wagtail-treemodeladmin-1.4.0.tar.gz.

File metadata

  • Download URL: wagtail-treemodeladmin-1.4.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for wagtail-treemodeladmin-1.4.0.tar.gz
Algorithm Hash digest
SHA256 b0118d4b4339265cb848f3b0808a5ffc05d92475c6b1ef58b4564f3c27c8005d
MD5 96e07048a7b7d0b297444ea8e2d0966b
BLAKE2b-256 0f26d3c2131f20509c2972ce2a236c6b43d2aa2d6750e24d4380eaacb8fc8bd6

See more details on using hashes here.

Provenance

File details

Details for the file wagtail_treemodeladmin-1.4.0-py2.py3-none-any.whl.

File metadata

  • Download URL: wagtail_treemodeladmin-1.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for wagtail_treemodeladmin-1.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 355fdb1d8b9b04f7baa44ded76ea656b6a1c4cf39b57969f7f11c8fb1f59bf42
MD5 591748772f18f3f9b58ae98b9c96f2f1
BLAKE2b-256 3406a61b4e34636ee578bbdc0350e8d4b5558ce550f0a60f60ab2c8f8efdbf7c

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page