Skip to content

develtech/django-polymorphic-tree

 
 

Repository files navigation

image

image

image

image

image

django-polymorphic-tree

This package combines django-mptt with django-polymorphic. You can write Django models that form a tree structure where each node can be a different model type.

Example uses:

  • Build a tree of organisation and company types (e.g. Partner, Reseller, Group and Customer)
  • Build a tree of a root node, category nodes, leaf nodes, each with custom fields.
  • Build a todo list of projects, categories and items.
  • Build a book of chapters, sections, and pages.

Origin

This code was created in django-fluent-pages, and extracted to become a separate package. This was done during contract work at Leukeleu (known for django-fiber).

Installation

First install the module, preferably in a virtual environment:

pip install django-polymorphic-tree

Or install the current repository:

pip install -e git+https://github.com/django-polymorphic/django-polymorphic-tree.git#egg=django-polymorphic-tree

The main dependencies are django-mptt and django-polymorphic, which will be automatically installed.

Configuration

Next, create a project which uses the application:

cd ..
django-admin.py startproject demo

Add the following to settings.py:

Usage

The main feature of this module is creating a tree of custom node types. It boils down to creating a application with 2 files:

The models.py file should define the custom node type, and any fields it has:

The admin.py file should define the admin, both for the child nodes and parent:

The child_models attribute defines which admin interface is loaded for the edit and delete page. The list view is still rendered by the parent admin.

Tests

To run the included test suite, execute:

./runtests.py

To test support for multiple Python and Django versions, you need to follow steps below:

  • install project requirements in virtual environment
  • install python 2.7, 3.3, 3.4, 3.5, 3.6 python versions through pyenv (See pyenv (Linux) or Homebrew (Mac OS X).)
  • create .python-version file and add full list of installed versions with which project have to be tested, example:

    2.6.9
    2.7.13
    3.3.6
    3.4.5
    3.5.2
    3.6.0
  • run tox from the repository root:

    pip install tox
    tox

Python 2.7, 3.3, 3.4, 3.5 and 3.6 and django 1.7, 1.8, 1.9, 1.10 and 1.11 are the currently supported versions.

Todo

  • Sphinx Documentation

Contributing

This module is designed to be generic. In case there is anything you didn't like about it, or think it's not flexible enough, please let us know. We'd love to improve it!

If you have any other valuable contribution, suggestion or idea, please let us know as well because we will look into it. Pull requests are welcome too. :-)

About

Polymorphic MPTT tree support for models

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 80.7%
  • HTML 10.7%
  • JavaScript 4.4%
  • CSS 4.2%