X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/fb8a270fa22abc217efc471d860c76d5a2352c61..943e8bc4af0c11b0ace3811199e3b0844c4c3fbc:/philo/models/base.py diff --git a/philo/models/base.py b/philo/models/base.py index cf420c7..1726d19 100644 --- a/philo/models/base.py +++ b/philo/models/base.py @@ -1,25 +1,31 @@ +from UserDict import DictMixin + from django import forms -from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic from django.core.exceptions import ObjectDoesNotExist from django.core.validators import RegexValidator +from django.db import models from django.utils import simplejson as json from django.utils.encoding import force_unicode +from mptt.models import MPTTModel, MPTTModelBase, MPTTOptions + from philo.exceptions import AncestorDoesNotExist from philo.models.fields import JSONField -from philo.utils import ContentTypeRegistryLimiter, ContentTypeSubclassLimiter from philo.signals import entity_class_prepared +from philo.utils import ContentTypeRegistryLimiter, ContentTypeSubclassLimiter from philo.validators import json_validator -from UserDict import DictMixin -from mptt.models import MPTTModel, MPTTModelBase, MPTTOptions class Tag(models.Model): + """A simple, generic model for tagging.""" + #: A CharField (max length 255) which contains the name of the tag. name = models.CharField(max_length=255) + #: A CharField (max length 255) which contains the tag's unique slug. slug = models.SlugField(max_length=255, unique=True) def __unicode__(self): + """Returns the value of the :attr:`name` field""" return self.name class Meta: @@ -38,7 +44,7 @@ class Titled(models.Model): abstract = True -#: An instance of :class:`ContentTypeRegistryLimiter` which is used to track the content types which can be related to by ForeignKeyValues and ManyToManyValues. +#: An instance of :class:`ContentTypeRegistryLimiter` which is used to track the content types which can be related to by :class:`ForeignKeyValue`\ s and :class:`ManyToManyValue`\ s. value_content_type_limiter = ContentTypeRegistryLimiter() @@ -338,7 +344,7 @@ class TreeManager(models.Manager): def get_with_path(self, path, root=None, absolute_result=True, pathsep='/', field='slug'): """ - If ``absolute_result`` is ``True``, returns the object at ``path`` (starting at ``root``) or raises a :exception:`DoesNotExist` exception. Otherwise, returns a tuple containing the deepest object found along ``path`` (or ``root`` if no deeper object is found) and the remainder of the path after that object as a string (or None if there is no remaining path). + If ``absolute_result`` is ``True``, returns the object at ``path`` (starting at ``root``) or raises an :class:`~django.core.exceptions.ObjectDoesNotExist` exception. Otherwise, returns a tuple containing the deepest object found along ``path`` (or ``root`` if no deeper object is found) and the remainder of the path after that object as a string (or None if there is no remaining path). .. note:: If you are looking for something with an exact path, it is faster to use absolute_result=True, unless the path depth is over ~40, in which case the high cost of the absolute query may make a binary search (i.e. non-absolute) faster. @@ -349,7 +355,8 @@ class TreeManager(models.Manager): :param absolute_result: Whether to return an absolute result or do a binary search :param pathsep: The path separator used in ``path`` :param field: The field on the model which should be queried for ``path`` segment matching. - :returns: An instance if absolute_result is True or (instance, remaining_path) otherwise. + :returns: An instance if ``absolute_result`` is ``True`` or an (instance, remaining_path) tuple otherwise. + :raises django.core.exceptions.ObjectDoesNotExist: if no object can be found matching the input parameters. """