X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/c0d303555a7ceb29fcaf03d067fb871476fe4c53..ca2138fef978345b9076a2f855ed434a0bac65e1:/models/base.py diff --git a/models/base.py b/models/base.py index 37ab247..202c2f3 100644 --- a/models/base.py +++ b/models/base.py @@ -402,10 +402,18 @@ class TreeModel(MPTTModel): slug = models.SlugField(max_length=255) def get_path(self, root=None, pathsep='/', field='slug'): + if root == self: + return '' + if root is not None and not self.is_descendant_of(root): raise AncestorDoesNotExist(root) - return pathsep.join([getattr(parent, field, '?') for parent in list(self.get_ancestors()) + [self]]) + qs = self.get_ancestors() + + if root is not None: + qs = qs.filter(level__gt=root.level) + + return pathsep.join([getattr(parent, field, '?') for parent in list(qs) + [self]]) path = property(get_path) def __unicode__(self):