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 wagtail-modeladmin that allows for a page explorer-like navigation of Django model relationships within the Wagtail admin.

Dependencies

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_modeladmin if it's not already) as an installed app in your Django settings.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 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.11.0.tar.gz (182.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wagtail_treemodeladmin-1.11.0-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file wagtail_treemodeladmin-1.11.0.tar.gz.

File metadata

  • Download URL: wagtail_treemodeladmin-1.11.0.tar.gz
  • Upload date:
  • Size: 182.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for wagtail_treemodeladmin-1.11.0.tar.gz
Algorithm Hash digest
SHA256 357a619589168ee558a1d96249a46575d973a65c59a7f824ace04c0878e5d7d7
MD5 adef446d80c768a3360151f0dd496fec
BLAKE2b-256 c97ab7eed8892f8a61e4076c76e7343cd29aa8510ab0d681203516367b05ae45

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_treemodeladmin-1.11.0.tar.gz:

Publisher: release.yml on cfpb/wagtail-treemodeladmin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wagtail_treemodeladmin-1.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_treemodeladmin-1.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 836ebe09bd221106d9db5c40398675dae9b2e1a9f81c8e0c44cc1abacdb280b7
MD5 37d52de03f6f4ed5a23c3f1e344cab3a
BLAKE2b-256 3789484e02bf43b2cd259e7646eaf7a1bfdf4739fd042df87441f129ec1cf550

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_treemodeladmin-1.11.0-py3-none-any.whl:

Publisher: release.yml on cfpb/wagtail-treemodeladmin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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