from django import forms
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
-from django.core.exceptions import ObjectDoesNotExist
+from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.db import models
from django.utils import simplejson as json
from philo.validators import json_validator
-__all__ = ('Tag', 'value_content_type_limiter', 'register_value_model', 'unregister_value_model', 'JSONValue', 'ForeignKeyValue', 'ManyToManyValue', 'Attribute', 'Entity', 'TreeEntity')
+__all__ = ('Tag', 'value_content_type_limiter', 'register_value_model', 'unregister_value_model', 'JSONValue', 'ForeignKeyValue', 'ManyToManyValue', 'Attribute', 'Entity', 'TreeEntity', 'SlugTreeEntity')
class Tag(models.Model):
"""
return mapper(self)
- attributes = property(get_attribute_mapper)
+
+ @property
+ def attributes(self):
+ if not hasattr(self, '_attributes'):
+ self._attributes = self.get_attribute_mapper()
+ return self._attributes
class Meta:
abstract = True
else:
mapper = AttributeMapper
return super(TreeEntity, self).get_attribute_mapper(mapper)
- attributes = property(get_attribute_mapper)
def __unicode__(self):
return self.path
return super(SlugTreeEntity, self).get_path(root, pathsep, field)
path = property(get_path)
+ def clean(self):
+ if self.parent is None:
+ try:
+ self._default_manager.exclude(pk=self.pk).get(slug=self.slug, parent__isnull=True)
+ except self.DoesNotExist:
+ pass
+ else:
+ raise ValidationError(self.unique_error_message(self.__class__, ('parent', 'slug')))
+
class Meta:
unique_together = ('parent', 'slug')
abstract = True
\ No newline at end of file