X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/82e22de23b182353e35aa4e2fde0c08f4df5653f..9b40768160da75802636fc2b45c1f68bd36fd7bd:/models/base.py diff --git a/models/base.py b/models/base.py index 81e557f..9da9230 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 @@ -53,6 +54,7 @@ class Attribute(models.Model): class Meta: app_label = 'philo' + unique_together = ('key', 'entity_content_type', 'entity_object_id') value_content_type_limiter = ContentTypeRegistryLimiter() @@ -81,6 +83,7 @@ class Relationship(models.Model): class Meta: app_label = 'philo' + unique_together = ('key', 'entity_content_type', 'entity_object_id') class QuerySetMapper(object, DictMixin): @@ -249,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: @@ -273,7 +278,7 @@ class TreeModel(models.Model): abstract = True -class TreeEntity(TreeModel, Entity): +class TreeEntity(Entity, TreeModel): @property def attributes(self): if self.parent: