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',)
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",)}
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
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
inlines = [ContentletInline, ContentReferenceInline] + ViewAdmin.inlines
-class TemplateAdmin(admin.ModelAdmin):
+class TemplateAdmin(TreeAdmin):
prepopulated_fields = {'slug': ('name',)}
fieldsets = (
(None, {
def get_with_path(self, path, root=None, absolute_result=True, pathsep='/', field='slug'):
"""
- Given a <pathsep>-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