X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/983293d923dcede8362ee17b27fc825b2a466096..855ec6e1d29382dcbbfa63aece9e3b127b8ecf11:/models/base.py?ds=sidebyside diff --git a/models/base.py b/models/base.py index 2a94daa..27c45dc 100644 --- a/models/base.py +++ b/models/base.py @@ -3,6 +3,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic from django.utils import simplejson as json from django.core.exceptions import ObjectDoesNotExist +from philo.exceptions import AncestorDoesNotExist from philo.utils import ContentTypeRegistryLimiter from philo.signals import entity_class_prepared from UserDict import DictMixin @@ -240,7 +241,7 @@ class TreeManager(models.Manager): class TreeModel(models.Model): objects = TreeManager() parent = models.ForeignKey('self', related_name='children', null=True, blank=True) - slug = models.SlugField() + slug = models.SlugField(max_length=255) def has_ancestor(self, ancestor): parent = self @@ -251,7 +252,9 @@ class TreeModel(models.Model): return False def get_path(self, root=None, pathsep='/', field='slug'): - if root is not None and self.has_ancestor(root): + if root is not None: + if not self.has_ancestor(root): + raise AncestorDoesNotExist(root) path = '' parent = self while parent and parent != root: @@ -275,7 +278,7 @@ class TreeModel(models.Model): abstract = True -class TreeEntity(TreeModel, Entity): +class TreeEntity(Entity, TreeModel): @property def attributes(self): if self.parent: