All Projects → django-polymorphic → Django Polymorphic Tree

django-polymorphic / Django Polymorphic Tree

Licence: other
Polymorphic MPTT tree support for models

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Polymorphic Tree

Requery
Store e run queries on database to help system manager of a Django website
Stars: ✭ 12 (-92.11%)
Mutual labels:  django, django-admin
Django Polymorphic
Improved Django model inheritance with automatic downcasting
Stars: ✭ 1,135 (+646.71%)
Mutual labels:  django, django-admin
Django Suit Daterange Filter
Filter for django-admin allowing lookups by date range
Stars: ✭ 13 (-91.45%)
Mutual labels:  django, django-admin
Django Phantom Theme
Phantom is theme for django admin with many widgets, based on Twitter bootstrap 3.x.
Stars: ✭ 18 (-88.16%)
Mutual labels:  django, django-admin
Django Admin Relation Links
An easy way to add links to relations in the Django Admin site.
Stars: ✭ 87 (-42.76%)
Mutual labels:  django, django-admin
Django Blogging System
This is blog system created using Django 1.11.4 and Python3
Stars: ✭ 11 (-92.76%)
Mutual labels:  django, django-admin
Django Admin Numeric Filter
Numeric filters for Django admin
Stars: ✭ 46 (-69.74%)
Mutual labels:  django, django-admin
Django Ordered Model
Get your Django models in order
Stars: ✭ 476 (+213.16%)
Mutual labels:  django, django-admin
Awesome Django
Repository mirror of GitLab: https://gitlab.com/rosarior/awesome-django This repository is not monitored for issues, use original at GitLab.
Stars: ✭ 8,527 (+5509.87%)
Mutual labels:  django, django-admin
Django Admin Material
A Django Admin interface based on Material Design by Google
Stars: ✭ 74 (-51.32%)
Mutual labels:  django, django-admin
Django Admin Bootstrap
Responsive Theme for Django Admin With Sidebar Menu
Stars: ✭ 787 (+417.76%)
Mutual labels:  django, django-admin
Django Subadmin
A special kind of ModelAdmin that allows it to be nested within another ModelAdmin
Stars: ✭ 120 (-21.05%)
Mutual labels:  django, django-admin
Awesome Django
The Best Django Resource, Awesome Django for mature packages.
Stars: ✭ 591 (+288.82%)
Mutual labels:  django, django-admin
Django Oml
Object Moderation Layer
Stars: ✭ 12 (-92.11%)
Mutual labels:  django, django-admin
Django Pagedown
A django app that allows the easy addition of Stack Overflow's "PageDown" markdown editor to a django form field, whether in a custom app or the Django Admin
Stars: ✭ 500 (+228.95%)
Mutual labels:  django, django-admin
E Commerce 2 django
Guest register, user register, user login, user logout, account home page, product view history, change password, reset password, change name, send activation email when register, resend activation email, add shipping address, add billing address, add nickname to the addresses, edit shipping address, edit billing address, view list of your addresses, reuse shipping addresses when order products, reuse billing addresses when ordeer products, show sales analytics if staff or admin only using -chart.js-, get analytics data with Ajax, receive marketing email, change if user will receive marketing email or not by admin, send contact message with Ajax, products list, product detail, download product detail as a PDF file, download digital product files -if the user purchased that digital product only-, orders list, list of digital products files, order detail, download order detail as a PDF file, verify order ownership with Ajax -to secure order detail page-, show cart products, add or remove product from cart, checkout page, thanks page when order placed successfully, add or reuse payment method, add or reuse payment method with Ajax, search products by title, search products by description, search products by price, search products by tag title, write tags for products -by admin only-, auto fill contact email, full name if user logged in.
Stars: ✭ 20 (-86.84%)
Mutual labels:  django, django-admin
Django Flat Theme
A flat theme for Django admin interface. Modern, fresh, simple.
Stars: ✭ 415 (+173.03%)
Mutual labels:  django, django-admin
Django Nested Admin
Django admin classes that allow for nested inlines
Stars: ✭ 463 (+204.61%)
Mutual labels:  django, django-admin
Awesome Django Cn
Django 优秀资源大全。
Stars: ✭ 1,153 (+658.55%)
Mutual labels:  django, django-admin
Django Fluent Pages
A flexible, scalable CMS with custom node types, and flexible block content.
Stars: ✭ 103 (-32.24%)
Mutual labels:  django, django-admin

.. image:: https://img.shields.io/travis/django-polymorphic/django-polymorphic-tree/master.svg?branch=master :target: http://travis-ci.org/django-polymorphic/django-polymorphic-tree .. image:: https://img.shields.io/pypi/v/django-polymorphic-tree.svg :target: https://pypi.python.org/pypi/django-polymorphic-tree/ .. image:: https://img.shields.io/badge/wheel-yes-green.svg :target: https://pypi.python.org/pypi/django-polymorphic-tree/ .. image:: https://img.shields.io/pypi/l/django-polymorphic-tree.svg :target: https://pypi.python.org/pypi/django-polymorphic-tree/ .. image:: https://img.shields.io/codecov/c/github/django-polymorphic/django-polymorphic-tree/master.svg :target: https://codecov.io/github/django-polymorphic/django-polymorphic-tree?branch=master

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:

.. code:: python

INSTALLED_APPS += (
    'polymorphic_tree',
    'polymorphic',
    'mptt',
)

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:

.. code:: python

from django.db import models
from django.utils.translation import ugettext_lazy as _
from polymorphic_tree.models import PolymorphicMPTTModel, PolymorphicTreeForeignKey


# A base model for the tree:

class BaseTreeNode(PolymorphicMPTTModel):
    parent = PolymorphicTreeForeignKey('self', blank=True, null=True, related_name='children', verbose_name=_('parent'))
    title = models.CharField(_("Title"), max_length=200)

    class Meta(PolymorphicMPTTModel.Meta):
        verbose_name = _("Tree node")
        verbose_name_plural = _("Tree nodes")


# Create 3 derived models for the tree nodes:

class CategoryNode(BaseTreeNode):
    opening_title = models.CharField(_("Opening title"), max_length=200)
    opening_image = models.ImageField(_("Opening image"), upload_to='images')

    class Meta:
        verbose_name = _("Category node")
        verbose_name_plural = _("Category nodes")


class TextNode(BaseTreeNode):
    extra_text = models.TextField()

    # Extra settings:
    can_have_children = False

    class Meta:
        verbose_name = _("Text node")
        verbose_name_plural = _("Text nodes")


class ImageNode(BaseTreeNode):
    image = models.ImageField(_("Image"), upload_to='images')

    class Meta:
        verbose_name = _("Image node")
        verbose_name_plural = _("Image nodes")

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

.. code:: python

from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from polymorphic_tree.admin import PolymorphicMPTTParentModelAdmin, PolymorphicMPTTChildModelAdmin
from . import models


# The common admin functionality for all derived models:

class BaseChildAdmin(PolymorphicMPTTChildModelAdmin):
    GENERAL_FIELDSET = (None, {
        'fields': ('parent', 'title'),
    })

    base_model = models.BaseTreeNode
    base_fieldsets = (
        GENERAL_FIELDSET,
    )


# Optionally some custom admin code

class TextNodeAdmin(BaseChildAdmin):
    pass


# Create the parent admin that combines it all:

class TreeNodeParentAdmin(PolymorphicMPTTParentModelAdmin):
    base_model = models.BaseTreeNode
    child_models = (
        (models.CategoryNode, BaseChildAdmin),
        (models.TextNode, TextNodeAdmin),  # custom admin allows custom edit/delete view.
        (models.ImageNode, BaseChildAdmin),
    )

    list_display = ('title', 'actions_column',)

    class Media:
        css = {
            'all': ('admin/treenode/admin.css',)
        }


admin.site.register(models.BaseTreeNode, TreeNodeParentAdmin)

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.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.4.5 3.5.2 3.6.0

  • run tox from the repository root::

    pip install tox tox

Python 2.7, 3.4, 3.5 and 3.6 and django 1.8, 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. :-)

.. _Leukeleu: http://www.leukeleu.nl/ .. _django-fiber: https://github.com/ridethepony/django-fiber .. _django-fluent-pages: https://github.com/edoburu/django-fluent-pages .. _django-mptt: https://github.com/django-mptt/django-mptt .. _django-polymorphic: https://github.com/django-polymorphic/django-polymorphic

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].