From fea69c17983d2850352261760be568e792621013 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Mon, 15 Nov 2010 11:39:46 -0500 Subject: [PATCH] Added MPTTModelAdmin integration. Committed docstring changes for get_with_path. --- admin/base.py | 9 +++++++++ admin/nodes.py | 4 ++-- admin/pages.py | 4 ++-- models/base.py | 12 ++++++++---- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/admin/base.py b/admin/base.py index 0413dde..0d35cf6 100644 --- a/admin/base.py +++ b/admin/base.py @@ -7,6 +7,7 @@ from django.utils.html import escape from philo.models import Tag, Attribute from philo.forms import AttributeForm, AttributeInlineFormSet from philo.admin.widgets import TagFilteredSelectMultiple +from mptt.admin import MPTTModelAdmin COLLAPSE_CLASSES = ('collapse', 'collapse-closed', 'closed',) @@ -33,6 +34,14 @@ class EntityAdmin(admin.ModelAdmin): save_on_top = True +class TreeAdmin(MPTTModelAdmin): + pass + + +class TreeEntityAdmin(TreeAdmin, EntityAdmin): + pass + + class TagAdmin(admin.ModelAdmin): list_display = ('name', 'slug') prepopulated_fields = {"slug": ("name",)} diff --git a/admin/nodes.py b/admin/nodes.py index 093537e..45a3172 100644 --- a/admin/nodes.py +++ b/admin/nodes.py @@ -1,9 +1,9 @@ from django.contrib import admin -from philo.admin.base import EntityAdmin +from philo.admin.base import EntityAdmin, TreeEntityAdmin from philo.models import Node, Redirect, File -class NodeAdmin(EntityAdmin): +class NodeAdmin(TreeEntityAdmin): pass diff --git a/admin/pages.py b/admin/pages.py index 15b06d9..caeee05 100644 --- a/admin/pages.py +++ b/admin/pages.py @@ -1,7 +1,7 @@ from django.conf import settings from django.contrib import admin from django import forms -from philo.admin.base import COLLAPSE_CLASSES +from philo.admin.base import COLLAPSE_CLASSES, TreeAdmin from philo.admin.nodes import ViewAdmin from philo.models.pages import Page, Template, Contentlet, ContentReference from philo.forms import ContentletInlineFormSet, ContentReferenceInlineFormSet, ContentletForm, ContentReferenceForm @@ -48,7 +48,7 @@ class PageAdmin(ViewAdmin): inlines = [ContentletInline, ContentReferenceInline] + ViewAdmin.inlines -class TemplateAdmin(admin.ModelAdmin): +class TemplateAdmin(TreeAdmin): prepopulated_fields = {'slug': ('name',)} fieldsets = ( (None, { diff --git a/models/base.py b/models/base.py index c2c12ad..ce74489 100644 --- a/models/base.py +++ b/models/base.py @@ -282,10 +282,14 @@ class TreeManager(models.Manager): def get_with_path(self, path, root=None, absolute_result=True, pathsep='/', field='slug'): """ - Given a -separated path, fetch the matching model of this type. If the path - you're searching for is known to exist, it is always faster to use absolute_result=True. - Unless the path depth is over ~40, in which case the high cost of the absolute query - makes a binary search (i.e. non-absolute) faster. + Returns the object with the path, unless absolute_result is set to False, in which + case it returns a tuple containing the deepest object found along the path, and the + remainder of the path after that object as a string (or None if there is no remaining + path). Raises a DoesNotExist exception if no object is found with the given path. + + If the path you're searching for is known to exist, it is always faster to use + absolute_result=True - unless the path depth is over ~40, in which case the high cost + of the absolute query makes a binary search (i.e. non-absolute) faster. """ # Note: SQLite allows max of 64 tables in one join. That means the binary search will # only work on paths with a max depth of 127 and the absolute fetch will only work -- 2.20.1